eva21 Posted May 21, 2009 Share Posted May 21, 2009 $string = "it''s blue"; $update = mysql_query("UPDATE node SET color = '" . $string . "' WHERE id = '" . $rows['id'] . "'"); but all i get is "it" when i try to echo it....why? Quote Link to comment https://forums.phpfreaks.com/topic/159127-php-and-not-saving-right-to-the-database/ Share on other sites More sharing options...
MatthewJ Posted May 21, 2009 Share Posted May 21, 2009 Echo the query... it should be obvious then.. Just escape the apostorphe with a backslash instead... it is seeing the single quote as the close of the value Quote Link to comment https://forums.phpfreaks.com/topic/159127-php-and-not-saving-right-to-the-database/#findComment-839184 Share on other sites More sharing options...
Ken2k7 Posted May 21, 2009 Share Posted May 21, 2009 You need to escape the single quotes or it will mess up the single quote in your SQL. $string = "it''s blue"; $string = mysql_real_escape_string($string); $update = mysql_query("UPDATE node SET color = '" . $string . "' WHERE id = '" . $rows['id'] . "'"); Quote Link to comment https://forums.phpfreaks.com/topic/159127-php-and-not-saving-right-to-the-database/#findComment-839191 Share on other sites More sharing options...
eva21 Posted May 21, 2009 Author Share Posted May 21, 2009 It keeps cutting off the word? Quote Link to comment https://forums.phpfreaks.com/topic/159127-php-and-not-saving-right-to-the-database/#findComment-839197 Share on other sites More sharing options...
wildteen88 Posted May 21, 2009 Share Posted May 21, 2009 Where? In the databases or some other place. You need to be more specific. Quote Link to comment https://forums.phpfreaks.com/topic/159127-php-and-not-saving-right-to-the-database/#findComment-839209 Share on other sites More sharing options...
eva21 Posted May 21, 2009 Author Share Posted May 21, 2009 In the database. It keeps cutting off the word. Quote Link to comment https://forums.phpfreaks.com/topic/159127-php-and-not-saving-right-to-the-database/#findComment-839210 Share on other sites More sharing options...
wildteen88 Posted May 21, 2009 Share Posted May 21, 2009 How are you checking it in the database? Post the schema for your node table, maybe you have setup your color field incorrectly. Quote Link to comment https://forums.phpfreaks.com/topic/159127-php-and-not-saving-right-to-the-database/#findComment-839215 Share on other sites More sharing options...
eva21 Posted May 21, 2009 Author Share Posted May 21, 2009 Im checking it in the actual database. I see its not saving correctly Quote Link to comment https://forums.phpfreaks.com/topic/159127-php-and-not-saving-right-to-the-database/#findComment-839235 Share on other sites More sharing options...
MatthewJ Posted May 21, 2009 Share Posted May 21, 2009 wow guys... echo the query... it returns ... 'it''s'... for that value... you can't escape a single quote, with a single quote, inside of single quotes. Should make pretty good sense... change it to 'it\'s blue' and there shouldn't be a problem. Quote Link to comment https://forums.phpfreaks.com/topic/159127-php-and-not-saving-right-to-the-database/#findComment-839261 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.