This should be an easy question, I googled it and was noytable to get it working 100%.
I have a sql DB which records people signing up via a form for a newsletter/group. I have the form working fine where it inserts the data into the Db correctly. I now want to create another form that removes people form the database, aka a remove me type thing.
I have a simple form set up that asks for their email and I want the php to look at the DB, find a record that has the same email address and then removes that record from the DB.
I've been working with this sample
$dbuser="username";
$dbpass="password";
$dbname="mydata"; //the name of the database
$chandle = mysql_connect("localhost", $dbuser, $dbpass)
or die("Connection Failure to Database");
mysql_select_db($dbname, $chandle) or die ($dbname . " Database not found. " . $dbuser);
$mainsection="links"; //The name of the table where web links are stored
$idno=10;
$query1="delete from " . $mainsection . " where id = " . $idno;
mysql_db_query($dbname, $query1) or die("Failed Query of " . $query1);
echo "Link with ID " . $idno . " has been deleted as requested.<br>";
}
and I have changed it a bit so it looks like this
<?php
$email = $_POST['email2'];
if (!preg_match("/^([a-z0-9._-](\+[a-z0-9])*)+@[a-z0-9.-]+\.[a-z]{2,6}$/i", $email)) {
die ('The email you provided appears to have an error, please check it and submit the registration again.');
}
$email = $_POST['email2'];
$dbname="sampledb";
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("sampledb") or die(mysql_error());
$mainsection="group"; //The name of the table where web links are stored
$idno= $email;
$query1="delete from " . $mainsection . " where email = " . $idno;
mysql_db_query($dbname, $query1) or die("Failed Query of " . $query1);
echo "Link with ID " . $idno . " has been deleted as requested.<br>";
?>
Obviously, I am sure to you guys, it does not work. I get "Failed Query of delete from group where email = email@email.com"
The "group" table in the specified Db does have a record with that email listed in the "email" column. Each record is 9 entries and "email" is the first entry and is also the primary/index entry for that record.