udate command SQL Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ddtpmyra
    Contributor
    • Jun 2008
    • 333

    #1

    udate command SQL Error

    I have this below script and mysql didn't get thru I tried to print the sql query every things is fine it's just somehow can't update my table. What's wrong?

    [PHP]
    # Gather all required data
    $FirstName = $_POST['FirstName'];
    $LastName = $_POST['LastName'];

    # INSERT SQL query
    $query="INSERT INTO contact (FirstName,Last Name)
    VALUES (
    '{$FirstName}',
    '{$LastName}'
    )";

    echo "$query";
    # Execute the INSERT QUERY
    $result = mysql_query($qu ery, $dbLink) ;


    if($result){
    echo "Successful<BR> ";

    }
    else {
    echo "ERROR";
    }
    mysql_close();



    #Close the mysql connection
    mysql_close($db Link);

    [/PHP]
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, ddtpmyra.

    Try checking for error this way:
    [code=php]
    if( mysql_errno() )
    {
    exit(mysql_erro r());
    }
    [/code]

    Returns the numerical value of the error message from previous MySQL operation

    Returns the text of the error message from previous MySQL operation

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      there might be something wrong with the connection resource. check if $dbLink is valid.

      regards

      Comment

      • ddtpmyra
        Contributor
        • Jun 2008
        • 333

        #4
        hi pbmods,

        Your syntax works I was able to catch what's my sql error is....

        thanks a lot!

        [PHP]if( mysql_error() )
        {
        exit(mysql_erro r());
        } [/PHP]

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          additional note:
          another common way to catch a db error is
          [PHP]mysql_query($sq l) or die("DB Error " . mysql_errno() . ": " . mysql_error());[/PHP]

          Comment

          • ddtpmyra
            Contributor
            • Jun 2008
            • 333

            #6
            Thanks Dormilich for the additional info

            Comment

            Working...