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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Updating Problem

    I am having trouble getting a code to update my db. I am sure that the variable is being passed and I *think* I have the code correct, however I get a "Error in SQL syntax."

    Here is the code:

    <?

    header("Refresh: 3; URL=item.php?StockNum=$ud_StockNum");
    include("dbinfo.inc.php");
    mysql_connect(localhost,$username,$password) or die ('I cannot connect to the database because: ' . mysql_error());;
    @mysql_select_db("forklift_used") or die( "Unable to select database");

    $query="UPDATE used SET Make='$ud_Make', Model='$ud_Model', Price='$ud_Price', Terms='$ud_Terms', SerialNum='$ud_SerialNum' WHERE StockNum='$ud_StockNum'";
    mysql_query($query) or die(MySQL_Error()); ;

    $query="UPDATE used SET Desc='$ud_Desc' WHERE StockNum='$ud_StockNum'";
    mysql_query($query) or die(MySQL_Error()); ;

    echo "Stock Number "; echo $ud_StockNum; echo " Updated. Please Wait...";


    mysql_close();


    ?>

    The first update statement works fine but the second results in the error. The only difference that I can see between the two is that the "Desc" variable is a text type field that includes HTML.

    Any help you can give!

    Thanks!

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    What's the error?

  • #3
    Az`
    Az` is offline
    New Coder
    Join Date
    Mar 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Put something like echo '1'; before each query: then you can tell which one it's halting on.

  • #4
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    The error.

    Here is the error I recieve. I know it is from the second update statement.

    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 'Desc='3,000# Lift Capacity


    Could it be because the Desc variable is of text type and is defined as:

    <B>3,000# Lift Capacity</B><BR>
    <BR>
    <BR>
    <BR>
    Serial Number W13456<BR>
    <BR>
    183" Lift<BR>
    <BR>
    3 Wheel Triple Mast<BR>
    <BR>
    172" TSU<BR>
    <BR>
    <BR>
    <BR>
    <I>Price Includes Charger</I><BR>
    <BR>


    Thanks

  • #5
    Az`
    Az` is offline
    New Coder
    Join Date
    Mar 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Before using the strings straight into the database, try putting addslashes($string).

  • #6
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I added the addslashes($string) but that didn't seem to help. Just to check, I changed the $desc variable to equal "test" so there would not be any errors.

    I still get the following error:

    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 'Desc='test' WHERE StockNum=64000' at line 1

    It is like I do have a syntax error but the statement is the same as the one above it. I don't get it. <sigh>

  • #7
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That's funny. (not really)

    Apparently you can have a variable named $desc and you can use it in a form but you can not do an update with desc or it errors. I guess it's back to PHP 101 for me.

    Sigh, I renamed the variable $longdesc and all is good.

    Thanks for your help!


  •  

    Posting Permissions

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