ecabrera Posted February 9, 2013 Share Posted February 9, 2013 (edited) I don't why mysqli_real_escape_string will not add escape strings it seems like it should $game = $_POST['game']; $submit = $_POST['submit']; if($submit){ require "scripts/db.ini.php"; $safe = mysqli_real_escape_string($db, $game); $insert = "INSERT INTO `games`(`game`) VALUES ('$safe')"; mysqli_query($db,$insert); } Edited February 9, 2013 by ecabrera Quote Link to comment https://forums.phpfreaks.com/topic/274238-mysqli_real_escape_string/ Share on other sites More sharing options...
Technocrat Posted February 9, 2013 Share Posted February 9, 2013 It looks like you are using $game and not $safe in your query Quote Link to comment https://forums.phpfreaks.com/topic/274238-mysqli_real_escape_string/#findComment-1411203 Share on other sites More sharing options...
ecabrera Posted February 9, 2013 Author Share Posted February 9, 2013 No thats no it Quote Link to comment https://forums.phpfreaks.com/topic/274238-mysqli_real_escape_string/#findComment-1411204 Share on other sites More sharing options...
Technocrat Posted February 9, 2013 Share Posted February 9, 2013 You have the default character set, set? Are you sure $db is active and connected? Do you have errors and warnings on? It might be surpessing something, like its disabled or something? If you do a dump or a string compare are they both exactly equal? Quote Link to comment https://forums.phpfreaks.com/topic/274238-mysqli_real_escape_string/#findComment-1411205 Share on other sites More sharing options...
ecabrera Posted February 9, 2013 Author Share Posted February 9, 2013 yes this works it inserts into the database but doesnt escape Quote Link to comment https://forums.phpfreaks.com/topic/274238-mysqli_real_escape_string/#findComment-1411207 Share on other sites More sharing options...
Jessica Posted February 9, 2013 Share Posted February 9, 2013 If it inserted correctly then it DID escape. What is the string you're inserting? Quote Link to comment https://forums.phpfreaks.com/topic/274238-mysqli_real_escape_string/#findComment-1411210 Share on other sites More sharing options...
ecabrera Posted February 9, 2013 Author Share Posted February 9, 2013 im inserting I'm a "foobar" shouldnt it escape it with / Quote Link to comment https://forums.phpfreaks.com/topic/274238-mysqli_real_escape_string/#findComment-1411211 Share on other sites More sharing options...
Jessica Posted February 9, 2013 Share Posted February 9, 2013 Like I said. If it inserted into the DB, then it was escaped. When you query your database what do you see?? Quote Link to comment https://forums.phpfreaks.com/topic/274238-mysqli_real_escape_string/#findComment-1411212 Share on other sites More sharing options...
ecabrera Posted February 9, 2013 Author Share Posted February 9, 2013 I'm a "foobar" Quote Link to comment https://forums.phpfreaks.com/topic/274238-mysqli_real_escape_string/#findComment-1411213 Share on other sites More sharing options...
tibberous Posted February 9, 2013 Share Posted February 9, 2013 im inserting I'm a "foobar" shouldnt it escape it with / I don't think you understand what it does. It replaces a couple characters, namely ', with \' so you can insert them into the database. Lets say you were inserting "Jim's Car" - if you didn't escape it, the query would fail, because the sql would read: INSERT INTO `games`(`game`) VALUES ('Jim's Car') So, when you escape it, it replaces Jim's Car with Jim\'s Car, you still get Jim's Car in the database, the backslashes are typically never seen. So... yeah - thats escaping. It doesn't just randomly add slashes to strings, and you'll never see the slashes if you insert it into the database instead of print it to the screen. Quote Link to comment https://forums.phpfreaks.com/topic/274238-mysqli_real_escape_string/#findComment-1411225 Share on other sites More sharing options...
Jessica Posted February 9, 2013 Share Posted February 9, 2013 I'm a "foobar" See, it worked... Quote Link to comment https://forums.phpfreaks.com/topic/274238-mysqli_real_escape_string/#findComment-1411226 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.