Forum Moderators: coopster

Message Too Old, No Replies

PHP adding a slash when passing variables

         

Nickpb

7:52 pm on Jun 26, 2005 (gmt 0)

10+ Year Member



Forgive me if I am being an absolute plank here, but I am new to PHP, and have a problem that is driving me mad.

I have one PHP page which displays a form, and requests input from the user. It then passes a string to another page, which is then passed to MySQL as the search arguement, and the results displayed.

The string from the first program is what I expected to see:
http://example.com/DisplayResults2.php3?arg=%20B_C1%20LIKE%20%22Sid%22

The variable I am passing (arg) is:

B_C1 LIKE "Sid"

so what is being passed looks correct to me.

In the second program, I use 'arg' as the arguement to SQL like this:

$query = "SELECT * FROM Baptisms WHERE $arg";

The trouble is that PHP seems to add an extra '\', so it actuall passes this:

SELECT * FROM Baptisms WHERE B_C1 LIKE \"Sid\"

I cannot for the life of me figure out why it adds extra '\', or how to get rid of them. If anyone can help, I will be eternally greatful.

Thanks.....Nick

[edited by: ergophobe at 10:06 pm (utc) on June 26, 2005]
[edit reason] URL exemplified as per Usage Agreement and forum charter [/edit]

Philosopher

8:01 pm on Jun 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sounds like you need to use the "stripslashes" function.

You can read up on it at [us3.php.net...]

Most likely either you have an "addslashes" function somewhere in your code, or magic_quotes_gpc is set to on in php.ini so the double quotes are being automatically escaped by slashes.

Nickpb

7:39 pm on Jun 27, 2005 (gmt 0)

10+ Year Member



You are an absolute *STAR* Thank you Philosopher, that now works a treat. I can't find any code that adds the slashes in the first place (I copied the code from elsewhere and 'tailored' it as necessary), so it's probably in the ini file as you suggested. I'll have to dig deeper.

APPRECIATE your help!

With regards......Nick

coopster

1:00 am on Jun 28, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Bet on the configuration (magic_quotes, as suggested). And welcome to WebmasterWorld, Nickpb.