Problem with updating a record

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dmyers
Forum Newbie
Posts: 7
Joined: Sat May 03, 2003 5:43 pm
Location: Texas, USA

Problem with updating a record

Post by dmyers »

:cry: I am having trouble updating a record in a mySQL database. I have tried everyting I can think of.

To start with uname is the username and is a number. At the bottom of the code I echo all of the variables to see if they are correct. It displays them all correctly.

Update.php is called from a page called edit.php which has a form and a submit button. The variable are passed from edit.php to update.php with the exception of the username, which is retrieved from a cookie that is set at login.

==== update.php ====

<?
mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name);
$result = mysql_query("UPDATE $db_table SET uname='$_COOKIE[USERNAME]', pass2=$password, email=$email WHERE uname='$_COOKIE[USERNAME]''")or DIE($result .' :'.mysql_error());
print '
<center>Variable Values</center><br>
<center><table border=1 bordercolor = "blue">
<tr>
<td> Username: </td>
<td>' . $_COOKIE[USERNAME] . '</td>
</tr>
<tr>
<td> Password: </td>
<td>' . $password . '</td>
</tr>
<tr>
<td> E-mail address: </td>
<td>' . $email . '</td>
</tr>
<tr>
<td> SQL: </td>
<td>' . $result . '</td>
</tr>
</table></center>';
?>

==== end of code ====

This is the error message I get when I run the update.

:You have an error in your SQL syntax near '@4-webdesign.net WHERE uname='14298691''' at line 1

The 14298691 is the username of a particular user and the @4-webdesign.net is the last part of that users email address.

If anyone has any ideas I would be forever greatful.
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

$result = mysql_query("UPDATE `$db_table` SET `uname`='$_COOKIE[USERNAME]', `pass2`='$password', `email`='$email' WHERE uname='$_COOKIE[USERNAME]''")or DIE($result .' :'.mysql_error());
Post Reply