Hi everyone,
I new to php and Mysql. My problem is that I created a script to delete a subscriber by email address. The email variable is coming from another page by form method post. It does what its suppose to do(deletes row), but I still receive an error message plus I know it could be cleaned up. Could someone point out what I am doing wrong and how I can clean it up. I'm barely understanding how to pull the results down without echoing and using it for other queries. This is my script and the error message:
<?php
if (isset($submit)) {
// do stuff
}
$dbh=mysql_connect ("localhost", "myusername", "mypassword") or die ('I cannot connect to the
database because: ' . mysql_error());
mysql_select_db ("mydb");
$result = mysql_query("SELECT * FROM news WHERE email='$email'"); //select all the
email address that equals varible
while($r=mysql_fetch_array($result)) //run the while loop
{
$id=$r["id"];//take out the id
{
$sql = "DELETE FROM news WHERE id=$id"; //delete from table using varable id
$result = mysql_query($sql);
echo "$email has been Successfully removed from NEWS LIST.";//acknowledge removal
}
"<BR>";
}
mysql_close ($dbh);//close connection
?>
It work but this is the error message:
Newsletter
somesubscrber@somedomain.com has been Successfully removed from NEWS LIST.
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/xxxxxx/public_html/remove.php on line 17
Thanks In Advance & Happy Holidays!