Results 1 to 5 of 5

Thread: PHP: problem updating mysql database

  1. #1
    9
    posts
    Registered User

    PHP: problem updating mysql database

    hi all,
    basically ive integrated the update.php into a page callef requestdetails.php, everything looks fine regarding the code, ive tried 3 hours of trial and error, chopping and changing and i keep getting an error everytime:

    ("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='this is the code typed in from the textbox' WHERE uploadid='5'' at line 1")

    Heres my code (connect to database is included in header, it connects because error message is showing results:

    <?php

    if (isset($_POST['Submit'])){

    $newdesc = $_POST['description'];
    $upid = $_POST['up_id'];

    $editdesc = mysql_query("UPDATE uploadref SET desc='" . mysql_real_escape_string($newdesc) . "' WHERE uploadid='$upid'")
    or die(mysql_error());
    if ($editdesc){
    $success_msg = '<font color="#009900">Your About section has been updated.</font>';
    } else {
    $error_msg = '<font color="#FF0000">Problems connecting to server, please try again later.</font>';
    }

    }
    ?>


    Pleasee please can someone help me on this, im goin to put my pc into intensive care ahah!
    Thanks
    Last edited by mung; August 19th, 2009 at 09:30 PM.

  2. #2
    1,627
    posts
    hugeExplosions = true;
    Quote Originally Posted by mung View Post
    hi all,
    basically ive integrated the update.php into a page callef requestdetails.php, everything looks fine regarding the code, ive tried 3 hours of trial and error, chopping and changing and i keep getting an error everytime:

    ("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='this is the code typed in from the textbox' WHERE uploadid='5'' at line 1")

    Heres my code (connect to database is included in header, it connects because error message is showing results:

    <?php

    if (isset($_POST['Submit'])){

    $newdesc = $_POST['description'];
    $upid = $_POST['up_id'];

    $editdesc = mysql_query("UPDATE uploadref SET desc='" . mysql_real_escape_string($newdesc) . "' WHERE uploadid='$upid'")
    or die(mysql_error());
    if ($editdesc){
    $success_msg = '<font color="#009900">Your About section has been updated.</font>';
    } else {
    $error_msg = '<font color="#FF0000">Problems connecting to server, please try again later.</font>';
    }

    }
    ?>

    Pleasee please can someone help me on this, im goin to put my pc into intensive care ahah!
    Thanks
    Tip of the day:

    Echo MySQL queries to the screen so you can see if they are REALLY valid!

    Do...

    Code:
    echo "UPDATE uploadref SET desc='" . mysql_real_escape_string($newdesc) . "' WHERE uploadid='$upid'";


    ...that first to see if the query is what you expect - if it is then yay, but bear in mind that if the UploadID contains a quote, it will kill your query because you didn't escape the special characters.

    What's the value for UploadID? Is it simply 5? Or is it "5'zt3[;40c"!?
    MS Paint FTW!


  3. #3
    9
    posts
    Registered User
    Quote Originally Posted by Charleh View Post
    Tip of the day:

    Echo MySQL queries to the screen so you can see if they are REALLY valid!

    Do...

    Code:
    echo "UPDATE uploadref SET desc='" . mysql_real_escape_string($newdesc) . "' WHERE uploadid='$upid'";
    ...that first to see if the query is what you expect - if it is then yay, but bear in mind that if the UploadID contains a quote, it will kill your query because you didn't escape the special characters.

    What's the value for UploadID? Is it simply 5? Or is it "5'zt3[;40c"!?

    Hi there, ive taken your advice on echo-in it out but it doesnt even get to the page to echo out, just returns error, im getting the results i want becuase the variables in the query im seeing in the error message are what i set them to (the textbox and uploadid values). the uploadid is numerical so no bugs there. im tearin my hair out over this haha!

  4. #4
    1,627
    posts
    hugeExplosions = true;
    Yeah the reason you don't get the page at all may be something to do with the "or die(mysql_error())" code you have on there.

    die() terminates the execution of the PHP page and clears the output buffer, then it writes just the error message to the buffer and displays it.

    Comment out the die and then retry (ooh that rhymes)

    Oh yeah, also I've noticed your error

    You are using DESC as the name of a column - in MySQL DESC is the keyword for DESCENDING in the ORDER BY clause

    Try adding `s round your column names (it's the key to the left of the 1 on your keyboard)

    so `desc`='blah de blah'

    That will sort it!
    Last edited by Charleh; August 20th, 2009 at 11:15 AM.
    MS Paint FTW!


  5. #5
    9
    posts
    Registered User
    Quote Originally Posted by Charleh View Post
    Yeah the reason you don't get the page at all may be something to do with the "or die(mysql_error())" code you have on there.

    die() terminates the execution of the PHP page and clears the output buffer, then it writes just the error message to the buffer and displays it.

    Comment out the die and then retry (ooh that rhymes)

    Oh yeah, also I've noticed your error

    You are using DESC as the name of a column - in MySQL DESC is the keyword for DESCENDING in the ORDER BY clause

    Try adding `s round your column names (it's the key to the left of the 1 on your keyboard)

    so `desc`='blah de blah'

    That will sort it!


    AHAHAHAHAH LEGENNNND! the desc trick worked, i feel like a numpty, i couldnt thank you enoughh KUDOSSS!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012