Jump to content

[SOLVED] Quick question re: escaping data


Recommended Posts

It's been a while since I've had to work with a database, so I'd just like to refresh my memory.  Data that has been escaped and stored in a database (say, by using mysql_real_escape_string()) will still be output correctly, right?  So:

   $testString = "'This is a quote,' she said";

      $testString = stripslashes($testString);

   $testString = mysql_real_escape_string($testString);

   $query = "INSERT INTO test_database (test_column) VALUES ('$testString');";
   $result = mysql_query($query);

   $query = "SELECT * FROM test_database";
   $result = mysql_query($query);
   $row = mysql_fetch_assoc($result);

   echo "{$row['test_column']}"; 


Is the output: 'This is a quote,' she said




is it: \'This is a quote,\' she said



Link to comment
Share on other sites

That depends on whether "magic_quotes_runtime" is enabled or not. If it is not enabled, the output will be

'This is a quote,' she said

if it is enabled, the output will be

\'This is a quote,\' she said




Easily thwarted with set_magic_quotes_runtime(0)

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

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

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.