php.ini and single quotes

Associate
Joined
27 Jun 2008
Posts
1,538
I stupidly deleted the php.ini file by accident when testing a batch file and didn't have a back-up and couldn't recover it. I've since created a new one fresh and everything seems to be working fine again except one thing I can't understand. I have various scripts which insert some data into a MySQL database. Now whenever anything with a single quote in it is entered it breaks the query with a syntax error. These scripts worked perfectly fine before I screwed up and deleted the php.ini. To get it working again I had to add addslashes() to all parts where a single quote may slip in.

So before I had this:

$name = substr($_POST['name'], 0, 256);

But had to change to this:

$name = addslashes(substr($_POST['name'], 0, 256));

The thing I can't see is the connection between the php.ini config file and the addslashes() function and why it worked before without it. I can only think there was an option in the file that I missed. I'm guessing it must have added slashes to single quotes in strings by default or something.
 
Could be that. I don't remember seeing it or changing it before. It's set to off in the file I'm using. I suppose I better leave it as it is as it's working now.
 
It's generally best to leave that off. That's the default setting now (wasn't always).
 
Back
Top Bottom