Shadowing Posted December 29, 2011 Share Posted December 29, 2011 I cant figure out why im having this problem. i stuck this at the top of my page on its own and it wont update the row to read <?php mysql_query("UPDATE pm SET read= 'read' WHERE pm_id = '".mysql_real_escape_string($_GET['pm_id'])."'"); ?> I echo $_GET['pm_id']; and that turn out correct and the number matches the pm_id on the row. everything is lowercase I typed read manually into the column and echo that and it showed read also I have this same exact line of code on another script that works fine. does someone see something im over looking? this is driving me crazy http://localhost/stargate/users/view.php?pm_id=1376672&inbox=2 <?php require("menu.php"); ?> <html> <body> <?php mysql_query("UPDATE pm SET read= 'read' WHERE pm_id = '".mysql_real_escape_string($_GET['pm_id'])."'"); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/253998-simple-database-update-issue/ Share on other sites More sharing options...
Pikachu2000 Posted December 29, 2011 Share Posted December 29, 2011 and the number matches the pm_id on the row. everything is lowercase How can a number be lower case? Quote Link to comment https://forums.phpfreaks.com/topic/253998-simple-database-update-issue/#findComment-1302076 Share on other sites More sharing options...
Shadowing Posted December 29, 2011 Author Share Posted December 29, 2011 yah i know its not case sensitive but mention it anyways lol added more details in my first post I even tried <?php mysql_query("UPDATE pm SET read= 'read'"); ?> that should make every row set to read right? the column is set to length of 6 and type VARCHAR Quote Link to comment https://forums.phpfreaks.com/topic/253998-simple-database-update-issue/#findComment-1302079 Share on other sites More sharing options...
Pikachu2000 Posted December 29, 2011 Share Posted December 29, 2011 Stop embedding the query string in the query execution. Form it in a variable, then use the variable to execute the query so you can echo the query string when things like this happen. Check to make sure the query executes successfully and if not, echo the query string and mysql_error(). Post any errors returned by MySQL. $query = "SELECT field FROM table"; if( $result = mysql_query($query) ) { // do whatever you need to do for a successful query execution } else { echo "<br>Query: $query<br>Produced error: " . mysql_error() . '<br>'; } Quote Link to comment https://forums.phpfreaks.com/topic/253998-simple-database-update-issue/#findComment-1302080 Share on other sites More sharing options...
Shadowing Posted December 29, 2011 Author Share Posted December 29, 2011 yah i need to start debugging more. this will help me out alot in the future Query: UPDATE pm SET read= 'read' WHERE pm_id = '1376672' Produced 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 'read= 'read' WHERE pm_id = '1376672'' at line 1 <?php $query = ("UPDATE pm SET read= 'read' WHERE pm_id = '".mysql_real_escape_string($_GET['pm_id'])."'"); if( $result = mysql_query($query) ) { } else { echo "<br>Query: $query<br>Produced error: " . mysql_error() . '<br>';} ?> wierd i have this code in another script that works fine <?php mysql_query("UPDATE users SET monitor= 'mod' WHERE goauld = '".mysql_real_escape_string($_POST['add_mod'])."'"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/253998-simple-database-update-issue/#findComment-1302087 Share on other sites More sharing options...
Pikachu2000 Posted December 29, 2011 Share Posted December 29, 2011 OK, now that you know how to get MySQL errors back, have a look here: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html Quote Link to comment https://forums.phpfreaks.com/topic/253998-simple-database-update-issue/#findComment-1302091 Share on other sites More sharing options...
Shadowing Posted December 29, 2011 Author Share Posted December 29, 2011 Huge help Pikachu thanks so much now i can debug stuff in the future I solved it with this <?php $query = ("UPDATE `pm` SET `read`= 'read' WHERE `pm_id` = '".mysql_real_escape_string($_GET['pm_id'])."'"); ?> I'll read the link you just gave me too Quote Link to comment https://forums.phpfreaks.com/topic/253998-simple-database-update-issue/#findComment-1302092 Share on other sites More sharing options...
Shadowing Posted December 29, 2011 Author Share Posted December 29, 2011 oh its because i was using a reserved word lol so thats what these are for `read` thats nice to know, thanks again Quote Link to comment https://forums.phpfreaks.com/topic/253998-simple-database-update-issue/#findComment-1302097 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.