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? Quote 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. Quote 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]))' Quote 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. Quote 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")."')"; Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.