I have a MySQL query that for some reason won't update the table it's supposed to.
mysql_query("INSERT INTO newsletteroptions (email, exists)
VALUES (\"".$_POST['email']."\", \"".$_POST['exists']."\")");
I've checked over my code and I'm sure that that is the line that is causing errors because the line before it was working -- I went in and edited the information in the database and it still truncated the table (see below)
I don't know why that snippet isn't working, because I copied it over from another document almost exactly the same that I created and tested, and it worked.
I also checked to make sure I spelled the table and field names correctly, and they all are.
This is the full code:
echo "
<form action=\"newsletterinfo.php?status=done\" method=\"post\" name=\"article\" target=\"_self\">
<a title=\"The email address the newsletter is sent from\">Newsletter email address:</a><input type=\"email\" name=\"email\" value=\"".$email."\"><br />
<label for=\"exists\">Activate newsletter?</label> <input type=\"checkbox\" id=\"exists\" name=\"exists\" value=\"true\" ".$checkyes."><br />
<input name=\"\" type=\"submit\" value=\"Update\" />
</form>";
}
else
{
$con = mysql_connect("WITHHELD","WITHHELD","WITHHELD");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("newsdb", $con);
//Add article to database
mysql_query("TRUNCATE TABLE newsletteroptions");
mysql_query("INSERT INTO newsletteroptions (email, exists)
VALUES (\"".$_POST['email']."\", \"".$_POST['exists']."\")");
mysql_close($con);
}