Re: handling ' with mysql/php insert and select

From: Date: Thu, 03 Jan 2008 19:37:12 +0000
Subject: Re: handling ' with mysql/php insert and select
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-266583@lists.php.net to get a copy of this message
> when I type the word blah's to my text box > variable, and then insert it into mysql after being ran through > mysql_real_escape_string(), it does: > > insert into contract (contract_id, responsibility) VALUES (15, 'blah\\\'s') It looks like magic quotes is turned on. Take a look at http://us2.php.net/magic_quotes. > and when I run that select statement in PHP it prints blah\'s on the > screen. I want it to print back blah's without the \. So what are my > options? run every variable through stripslashes(); before printing > them to the screen? Using stripslashes is a nice quick fix, but for a long term solution turn off magic_quotes and then update your data to remove the extra slashes. A simple way to do that is to loop through your database records, run stripslashes and update the database. As always be sure to backup your database before doing this, just to be safe! :) HTH, Brady

« previous php.general (#266583) next »