Page 1 of 1

Why so many backslashes??

Posted: Mon Dec 12, 2005 2:45 pm
by Luke
I am making a directory administration panel for my site, and the description line always somes up like this if there are apostrophies and I have to submit, and fix errors a bunch of times. I think it has something to do with the urlencode function because every time you submit it, it adds more backslashes. here is the code where it is printed:

Code: Select all

<tr>
     <td>Description of Business</td>
     <td><textarea type="text" class="<?php echo $_GET['e_desc'] ?>_text" name="desc" rows="4" cols="20" /><?php echo stripslashes($_GET['desc']) ?></textarea></td>
    </tr>
and the php function that encodes the url

Code: Select all

function make_query($array, $negate="NONE"){
    $query_string = "&";
    foreach($array as $key => $val){
        if($key != $negate && is_array($val)){
	        foreach($val as $k => $v){
	    		$query_string .= urlencode($key) . $k . "=" . $v . "&";
    		}
        }
        elseif($key != $negate){
            $query_string .= urlencode($key)."=".urlencode($val)."&";
        }
    }
    $query_string = substr($query_string, 0, -1);
    return $query_string;
}
and here is what I get
asd df \\\\\\\'asd\\\\\\\'fa\\\\\\\' sdf \\\\\\\'asdf\\\\\\\' asd\\\\\\\'f asd\\\\\\\'f a\\\\\\\'sdf
I can't really explain it any better than that... so sorry if it is confusing

Posted: Mon Dec 12, 2005 2:46 pm
by Chris Corbyn
gpc_magic_quotes is turned on ;)

Turn it off or use stripslashes() -- In the right places.

Posted: Mon Dec 12, 2005 2:50 pm
by Luke
alright...

Can I turn the magic quotes thing with ini_set?

I used stripslashes (if you look at the code above). Was it in the wrong place?

Posted: Mon Dec 12, 2005 2:53 pm
by Chris Corbyn
The Ninja Space Goat wrote:alright...

Can I turn the magic quotes thing with ini_set?
You could always try it ;) Hint Hint.

BTW... You want to stripslashes when the data is retreived FROM the textarea rather than when you put it back -- At least I've always done that but logically I dont see a difference :?

Posted: Mon Dec 12, 2005 2:55 pm
by Luke
thanks d11...

edit: ok I tried ini_set("magic_quotes_gpc", 0); and that did nothing... I will try a few more things with that...

Posted: Mon Dec 12, 2005 2:55 pm
by Chris Corbyn
Oh BTW... typo on my part (and memory loss :P)

It's magic_quotes_gpc not gpc_magic_quotes

Posted: Mon Dec 12, 2005 3:04 pm
by Luke
d11wtq wrote:You want to stripslashes when the data is retreived FROM the textarea
This worked... Thanks man,