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
https://forums.phpfreaks.com/topic/109542-solved-slashes-apearing-from-form-input/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.