Jump to content

[SOLVED] Quick question re: escaping data


KevinM1

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:

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

   if(get_magic_quotes_gpc()){
      $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

 

OR

 

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

 

?

Link to comment
https://forums.phpfreaks.com/topic/100146-solved-quick-question-re-escaping-data/
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

 

Ken

 

Easily thwarted with set_magic_quotes_runtime(0)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.