Jump to content

mysqli_real_escape_string


ecabrera

Recommended Posts

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 by ecabrera
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.