08-19-2009, 09:43 PM
|
#1
|
|
|
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..
|
|
|
08-20-2009, 04:50 AM
|
#2
|
|
|
Quote:
Originally Posted by mung
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!
|
|
|
08-20-2009, 08:26 AM
|
#3
|
|
|
Quote:
Originally Posted by Charleh
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!
|
|
|
08-20-2009, 12:13 PM
|
#4
|
|
|
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..
|
|
|
08-20-2009, 09:31 PM
|
#5
|
|
|
Quote:
Originally Posted by Charleh
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!
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 04:16 PM.
|
|