Hey everyone,
I am fairly new at php, and was wondering if there is anyway to dynamically displaying the information from a database after being altered by a form. I am trying to create a list of email addresses from a database then have a user either add or remove those email addresses. Then the user will see them added or removed. I kinda figured out a sort of cheating way to add it. But the big issue is to remove it. here is my code:
<body>
<form>
<p><input type="text" size="50" name="add_email">
<input type="submit" name="add" value="Add Email Address" /></p>
<p><input type="text" size="50" name="remove_email">
<input type="submit" name="remove" value="Remove Email Address" /></p></p>
</form>
<?php
$db = mysql_connect("localhost", "user", "pass")
or die ("could not connect, please contact system admin");
$selected = mysql_select_db(bmkphot_emailer, $db);
if ($selected == false)
echo mysql_errno() . ": " . mysql_error() . "<BR>";
$query = "SELECT * FROM email";
$result = mysql_query($query) or die("query failed");
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach ($line as $col_value) {
print "<p>$col_value</p>\n";}
}
if(isset($add))
{
$query = "insert into email values ('add_email')";
mysql_query($query) or die("didn't work");
print "$add_email";}
unset($add);
if(isset($remove))
{
$query = "delete from email where address = '$remove_email'";
mysql_query($query) or die("didn't work");
$query = "SELECT * FROM email";
$result = mysql_query($query) or die("query failed");
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach ($line as $col_value) {
print "<p>$col_value</p>\n";}
}}
unset($remove);
?>
</body>
Any sort of help would be greatly appreitiated 🙂