Click to See Complete Forum and Search --> : POST variables not passed correctly when containing quotes


angrytuna
08-08-2003, 01:21 PM
Good morning to the forum! (morning here, anyways).

I have a problem. I am passing a string of text via POST that may or may not contain quotation marks. The problem is, PHP is doing something strange; it keeps chopping off the section containing the quotes. Code follows demonstrating this:


<html>
<head>
<title>Test Send</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
print "<font color='#FF0000'>".$_POST['test']."<br /></font>";
?>
<form action="test.php" method="post">
<input type="text" name="test" value="<?php print $_POST['test']; ?>">
<input type="submit">
</form>
</body>
</html>


If you enter a string like Hello "World", the variable prints as Hello \"World\" the first time, and Hello \ the second time. The backslashes get worse as you keep hitting the submit button. I have no idea why this is.
I would really appreciate anyone's help with solving this. Thank you in advance for even taking a look.

AT

pyro
08-08-2003, 05:27 PM
Look into stripslashes() (http://us2.php.net/manual/en/function.stripslashes.php)

Jeff Mott
08-08-2003, 06:04 PM
I'm actually a little curious if this is considered normal behaviour in PHP? Is the user expected to pass all input variables through stripslashes()?

pyro
08-08-2003, 10:18 PM
Yes, it is normal behaviour for PHP... Try this code out:

<?PHP
if (isset($_POST["submit"])) {
echo $_POST["mytext"];
}
?>
<form action="<?PHP echo $_SERVER["PHP_SELF"]; ?>" method="post">
<p><input type="text" name="mytext" value='te"st'><br>
<input type="submit" name="submit"></p>
</form>Nothing special going on, yet it will echo with the quotes escaped (backslash).