...

View Full Version : UPDATE command error



ccwebstuff
10-06-2004, 11:59 PM
I've probably stared at this so long which is why I can NOT see what the error is. This is a simple update - ID is unique and all of the values are from a $php:self post -- any ideas?


if (isset($submitpick))
{
$cDate = trim( $cDate);

$sql = "UPDATE SportsPicks SET date='$cDate',league='$cLeague',pick='$cPick',status='$cStatus' where id=". $_POST['pickid'] ;
if (mysql_query($sql, $dbh))
{
echo("<P>Sports Pick was changed.</P>");
}
else
{
echo("<P>Error changing this Sports Pick: " . mysql_error() . "</P>");
}
}

sad69
10-07-2004, 12:16 AM
Indenting and code tags would help us read this:


if (isset($submitpick)) {
$cDate = trim( $cDate);

$sql = "UPDATE SportsPicks SET date='$cDate',league='$cLeague',pick='$cPick',stat us='$cStatus' where id=". $_POST['pickid'] ;
if (mysql_query($sql, $dbh)) {
echo("<P>Sports Pick was changed.</P>");
}
else {
echo("<P>Error changing this Sports Pick: " . mysql_error() . "</P>");
}
}


It would further help if we knew what the error was. How do you know there was an error? What error message was displayed?

Have you tried running the SQL statement directly into MySQL (using the mysql console or phpMyAdmin)? If there's an error there, then there will be an error here..

Also, have you echo'd the values of $cLeague, $cPick, $cStatus, $_POST['pickid'], $sql? If any of these values are blank or have quotes in them, that could mess it up. You might want to consider escaping those variables..


Also, and this might sound dumb, but are you sure you're connected to the MySQL database? If not, mysql_error() will display nothing, and that's usually the reason...


Sadiq.

ccwebstuff
10-07-2004, 12:26 AM
Error changing this Sports Pick: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

These are the lines from my PHP code.
line 1 <html>
line 2 <head>
line 3 <title>

Actual code that I'm having problems with starts at line 29 shown above reformatted.

Needless to say VERY frustrating ... it has to be some kind of glitch in either quotes or something -- and I've tried so many things I'm literally making myself sick.

Fou-Lu
10-07-2004, 12:50 AM
If thats the identical code to what you are using, the sql is fragmented at the end of your id pick.



if (isset($submitpick))
{
$cDate = trim($cDate);

$sql = "UPDATE SportsPicks SET date='$cDate',league='$cLeague',pick='$cPick',stat us='$cStatus' where id='". $_POST['pickid'] . "'";
if (mysql_query($sql, $dbh))
{
echo("<P>Sports Pick was changed.</P>");
}
else
{
echo("<P>Error changing this Sports Pick: " . mysql_error() . "</P>");
}
}


Try that and see if it works. Check that space between the stat us to see if its supposed to be that way as well. And of course, check to make sure you have a connection, cause that would cause an error as well :p

sad69
10-07-2004, 12:50 AM
Again, try executing the SQL statement directly in MySQL, using either the MySQL console or phpMyAdmin with the values you're actually working with and see if that works.

Also:


echo $sql;


After you've declared $sql so you can see what query is actually getting executed. And try running that query in phpMyAdmin and that should help you with debugging it...

Sadiq.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum