magic quotes

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 13
Joined: Mon Mar 31, 2014 1:15 pm

Sat Apr 26, 2014 9:13 am

I have two different php files, that use the standard routine to sort out characters, one works one does not, one is used in reading data from an sql database, there other is in support of writing data, its this one that does not work. The standard routine is:

Code: Select all

function quote_smart($value, $handle) {

   if (get_magic_quotes_gpc()) {
       $value = stripslashes($value);
	   echo 1;

   if (!is_numeric($value)) {
	   $value = "'" . mysql_real_escape_string($value, $handle) . "'";
	   echo 0;
   return $value;
Both use the following to call the function:

Code: Select all

$uname = quote_smart($uname, $db_handle);
I have interupted the code and printed out the variable.

One as an example gives and answer of work, whereas the other one to write to SQL gives and answer of 'work', with the apostrophes.

Both go to different tables in the same database, clearly the work one wont write to the database.

I f I don't call them, then I get an error with $num_rows

any suggestions gratefully recieved.


php-forum Fan User
php-forum Fan User
Posts: 974
Joined: Mon Oct 01, 2012 12:32 pm

Sat Apr 26, 2014 9:22 am

You're working from old example code, using deprecated functions. Switch to PDO and use pdo->quote()

Post Reply