Jump to content

[SOLVED] slashes apearing from form input


dmccabe

Recommended Posts

when entering things in my form, if someone puts in an apostrophe ' then it is echo'd out as \'

 

eg:

 

O'brien = O\'brien

 

Why is this?

 

This is where the variable is set

 

	$surname = mysql_real_escape_string($_POST['surname']);

 

If I echo out the $surname then it has the \, however if I echo out $_POST['surname'], then the \ is not there.

 

 

Link to comment
Share on other sites

That's because of magic quotes.

I'm using the following code to prevent of magic_quotes:

<?php
if (get_magic_quotes_gpc()) { //Magic Quotes enabled?
	$_POST = array_map('stripslashesinarray', $_POST);
	$_GET = array_map('stripslashesinarray', $_GET);
	$_COOKIE = array_map('stripslashesinarray', $_COOKIE);
	$_REQUEST = array_map('stripslashesinarray', $_REQUEST);
}

function stripslashesinarray($value) {
	return (is_array($value) ? array_map('stripslashesinarray', $value):stripslashes($value));
}
?>

Put that code to the beginning of every PHP-page, where you need $_POST and so on.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.