Reputation: 7053
if(isset($_POST['admin_email']))
{
$conn= mysql_connect("localhost","root","","");
mysql_select_db("qasite" ,$conn) or die(mysql_error());
$email=mysql_escape_string($_POST['admin_email']);
mysql_query(" UPDATE admin_details
SET email='$email'
WHERE admin_id=1
") or trigger_error(mysql_error(),E_USER_ERROR);
echo 'Update was successful';
}
The update statment at the end appears, but no record appears in the database. By default I set the admin_id equal 1, and no update happens. Why is that?
Upvotes: 1
Views: 74
Reputation: 1776
but no record appears in the database.
You can use UPDATE
only on records that exist. If there is no record WHERE admin_id = 1, the query won't update non-existing rows.
You could use INSERT
and work with the ON DUPLICATE KEY UPDATE
. (then email should be an UNIQUE index).
Upvotes: 2
Reputation: 1678
You can change trigger_error
to die(mysql_error())
and see if it works better.
Upvotes: 0