Fairly new php scripter needs help
Posted: Wed Mar 18, 2009 7:52 pm
Hello to all. I am learning to script php/mysql using a book from HeadFirst. I have gotten to a situation where I cannot get the code in the lesson to work. One issue that I deal with is that the syntax in the book does not match what is in the book, so I have to hunt through the code until I get the correct syntax to work. On this issue, I do not get any results from running the script. Below is the code exactly as it is on the server. Please take a look and tell me where I am going wrong. Any help would be appreciated. Thanks
Code: Select all
<img src="blankface.jpg" width="161" height="350" alt="" style="float:right" />
<img name="elvislogo" src="elvislogo.gif" width="229" height="32" border="0" alt="Make Me Elvis" />
<p>Please select the email addresses to delete from the email list and click Remove</p>
<form method="post" form action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php
echo 'Testing database connection<br>';
$link = mysql_connect("localhost","****","****")
or die("Could not connect: " . mysql_error());
mysql_select_db("my_db", $link);
echo 'Database select successful<br>';
//Delete the customer rows (only if the form has been submitted)
if (isset($_POST['submit'])
{
foreach ($_POST['todelete'] as $delete_id)
{
mysql_query("SELECT first_name FROM email_list WHERE id = $delete_id");
mysql_query($link, mysql_query);
}
echo 'Customer(s) removed.<br />';
}
//Display the customer rows with checkboxes for deleting
mysql_query("SELECT FROM * email_list");
$result = mysql_query($link, mysql_query);
while($row = mysql_fetch_array($result))
{
echo '<input type="checkbox" value="' . $row['id'] . '" name="todelete[]" />';
echo $row['first_name'];
echo $row['last_name'];
echo $row['email'];
echo '<br />';
}
mysql_close($link);
?>
<input type="submit" name="submit" value="Remove Me" />
</form>