Fairly new php scripter needs help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
embtech
Forum Newbie
Posts: 10
Joined: Wed Mar 18, 2009 7:44 pm

Fairly new php scripter needs help

Post by embtech »

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>
 
 
Last edited by embtech on Wed Mar 18, 2009 9:27 pm, edited 1 time in total.
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Re: Fairly new php scripter needs help

Post by William »

Code: Select all

 
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 />';
}
 
There is no point in the second mysql_query() call. I also think you're going for "DELETE FROM email_list WHERE id = $delete_id" for the first query.

Code: Select all

 
mysql_query("SELECT FROM * email_list");
 
$result = mysql_query($link, mysql_query);
 
Should be

Code: Select all

 
$result = mysql_query("SELECT * FROM email_list");
 
embtech
Forum Newbie
Posts: 10
Joined: Wed Mar 18, 2009 7:44 pm

Re: Fairly new php scripter needs help

Post by embtech »

Thanks William for your quick response. I made the changes that you suggested and still get the same blank page. It looks like it is trying to run the while loop because there is a delay between when I call the script and then the blank screen. Any other ideas?
embtech
Forum Newbie
Posts: 10
Joined: Wed Mar 18, 2009 7:44 pm

Re: Fairly new php scripter needs help

Post by embtech »

bump....

Anyone have any ideas about the above?

Thanks in advance
Post Reply