burntheblobs Posted November 29, 2008 Share Posted November 29, 2008 When I send a variable through mysql that contains a ' (the variable being inserted points to text that contains the ' character) it creates an error in the query. Is there any way around this? Link to comment https://forums.phpfreaks.com/topic/134731-solved-sending-a-in-query-causes-an-error/ Share on other sites More sharing options...
corbin Posted November 29, 2008 Share Posted November 29, 2008 http://php.net/mysql_real_escape You might want to read up on sql injection. Link to comment https://forums.phpfreaks.com/topic/134731-solved-sending-a-in-query-causes-an-error/#findComment-701576 Share on other sites More sharing options...
burntheblobs Posted November 29, 2008 Author Share Posted November 29, 2008 Thank you for the link. I didn't even think about that kind of security flaw. I now have this in my code and for some reason it is bad sql syntax and it can't even execute the query now no matter what. 'sprintf('%s',mysqli_real_escape_string($_POST[Comment]))' Link to comment https://forums.phpfreaks.com/topic/134731-solved-sending-a-in-query-causes-an-error/#findComment-701825 Share on other sites More sharing options...
Mchl Posted November 29, 2008 Share Posted November 29, 2008 Show us some more code. Link to comment https://forums.phpfreaks.com/topic/134731-solved-sending-a-in-query-causes-an-error/#findComment-701851 Share on other sites More sharing options...
burntheblobs Posted November 30, 2008 Author Share Posted November 30, 2008 $query = "INSERT INTO post (Id,comment,first,second,third,posterIp,postDate) VALUES ('".mysqli_insert_id($cxn)."','sprintf('%s',mysqli_real_escape_string($_POST[Comment]))','$_POST[firstRating]', '$_POST[secondRating]','$_POST[thirdRating]','".getIp()."', '".date("Y/m/d")."')"; Link to comment https://forums.phpfreaks.com/topic/134731-solved-sending-a-in-query-causes-an-error/#findComment-702027 Share on other sites More sharing options...
str8thug843 Posted November 30, 2008 Share Posted November 30, 2008 $comment = mysql_real_escape_string($_POST['firstRating']); $firstrating = $_POST['firstRating']; $secondrating = $_POST['secondRating']; .. ect ect then in your values ('$comment', ' $firstrating', '$secondrating') .. ect Link to comment https://forums.phpfreaks.com/topic/134731-solved-sending-a-in-query-causes-an-error/#findComment-702052 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.