PHP to delete values in MySQL if conditions are met
Posted on 2002-04-27
I need a simple script to delete values in MySQL if certain conditions are met. Data would post via a HTTP form.
Condition 1: The form must have the email value specified.
Condition 2: The email must be present in the database if not it should notify the user
Condition 3: If the email does exist, delete the value and display a confirmation.
This is the script so far it doesn’t work but I think I am on the right track. Please advise. I am very new to PHP/MySQL. Thanks.
mysql_connect($host, $user, $pass) or die ("Unable to connect!");
mysql_select_db($db) or die ("Unable to select database!");
$remove = mysql_query("DELETE FROM emails WHERE email ='$email'") or die ("Your address could not be removed. Please try again later.");
$validemail = mysql_query("SELECT * from emails ");
while ($row = mysql_fetch_row($validemail))
if ($email =="")
echo ("You must enter a valid email address.");
elseif ($email != "$validemail")
echo ("The email was not found in the database");
else ($email == "$validemail");
echo ("Email has been removed");