Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2003
    Location
    Las Vegas
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    UPDATE command error

    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>");
    }
    }

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Indenting and code tags would help us read this:
    Code:
    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..

    Edit:
    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.
    Last edited by sad69; 10-07-2004 at 01:19 AM.

  • #3
    New to the CF scene
    Join Date
    Dec 2003
    Location
    Las Vegas
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error Msg I'm getting

    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.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    If thats the identical code to what you are using, the sql is fragmented at the end of your id pick.

    PHP Code:
    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
    Last edited by Fou-Lu; 10-07-2004 at 01:52 AM.

  • #5
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    PHP Code:
     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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •