Go Back   kirupaForum > Development > Server-Side (PHP, SQL, ASP.NET, etc.)

Reply
 
Thread Tools Display Modes
Old 08-19-2009, 09:43 PM   #1
mung
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; 08-19-2009 at 10:30 PM..
mung is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 08-20-2009, 04:50 AM   #2
Charleh
hugeExplosions = true;
Location Bolton!

Posts 1,608
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!

Charleh is offline   Reply With Quote
Old 08-20-2009, 08:26 AM   #3
mung
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!
mung is offline   Reply With Quote
Old 08-20-2009, 12:13 PM   #4
Charleh
hugeExplosions = true;
Location Bolton!

Posts 1,608
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!

__________________
MS Paint FTW!


Last edited by Charleh; 08-20-2009 at 12:15 PM..
Charleh is offline   Reply With Quote
Old 08-20-2009, 09:31 PM   #5
mung
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!
mung is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:16 PM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com