JJBlaha Posted November 15, 2006 Share Posted November 15, 2006 if($read == '0') {$sql2 = "UPDATE privatemessages SET read = '1' WHERE id='$id'";$result2 = @mysql_query($sql2,$connection);if($result2) {echo "great success!";} else {echo "you fail!";}}outputs you fail!i know the id whatever is there, and i know the read is set to 0 there so why doesnt the script work? Link to comment https://forums.phpfreaks.com/topic/27298-sql-update-problem/ Share on other sites More sharing options...
SharkBait Posted November 15, 2006 Share Posted November 15, 2006 Change it to read:[code]<?php$result2 = mysql_query($sql2, $connection) or die("MySQL Error: <br />{$sql2}<br /> ". mysql_error());?>[/code]the die() section will stop the rest of the script and the mysql_error() will output what is wrong if its a MySQL issue. Link to comment https://forums.phpfreaks.com/topic/27298-sql-update-problem/#findComment-124822 Share on other sites More sharing options...
JJBlaha Posted November 15, 2006 Author Share Posted November 15, 2006 MySQL Error:UPDATE privatemessages SET read = '1' WHERE id='7'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 = '1' WHERE id='7'' at line 1is what i get. Link to comment https://forums.phpfreaks.com/topic/27298-sql-update-problem/#findComment-124826 Share on other sites More sharing options...
trq Posted November 15, 2006 Share Posted November 15, 2006 I assume $read is NOT a string.[code=php:0]if($read == 0) {[/code] Link to comment https://forums.phpfreaks.com/topic/27298-sql-update-problem/#findComment-124829 Share on other sites More sharing options...
SharkBait Posted November 15, 2006 Share Posted November 15, 2006 read is a function of MySQLEnclose read with backticks (next to the 1 key) [code]<?phpUPDATE privatemessages set `read` = '1' WHERE id = '{$id}'?>[/code] Link to comment https://forums.phpfreaks.com/topic/27298-sql-update-problem/#findComment-124832 Share on other sites More sharing options...
JJBlaha Posted November 15, 2006 Author Share Posted November 15, 2006 Thanks that worked beautifully :) If i had chosen something other than read such as r121 i would not have had to do that? Link to comment https://forums.phpfreaks.com/topic/27298-sql-update-problem/#findComment-124834 Share on other sites More sharing options...
trq Posted November 15, 2006 Share Posted November 15, 2006 [quote]If i had chosen something other than read such as r121 i would not have had to do that?[/quote]yeah... didn't even pick up on that. read is a reserved word in MySql. Link to comment https://forums.phpfreaks.com/topic/27298-sql-update-problem/#findComment-124836 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.