First PHP page, so this is likely a problem surfacing out of something stupid I'm missing, but I'm not sure what. I'm following the tutorial on W3Schools to create a form with protection from XSS, but when I use the code<form method="post" action="<?php echo $_SERVER['PHP_SELF'); ?>">
, it is parsed such that the first >
is associated with the form
tag, so the quotes are mismatched, and the action doesn't complete correctly.
This is what the page looks like:
EDIT: Full Code Below
<body>
<?php
$fname = $lname = $email = $student = "";
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$email = $_POST["email"];
switch($_POST["student"])
{
case "u":
$student = "Undergraduate";
break;
case "g":
$student = "Graduate";
break;
default:
$student = "Non-Student";
}
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'); ?>">
<p>First Name: <input type="text" name="fname"> </p>
<p>Last Name: <input type="text" name="lname"> </p>
<p>Email: <input type="email" name="email"> </p>
<p>Student Status: <select name="student">
<option value="u">Undergraduate</option>
<option value="g">Graduate</option>
<option value="x">Non-Student</option>
</select> </p>
<input type="submit" value="Submit">
</form>
<?php
echo "<h3>Input:</h3>"
echo "Name: " . $fname . " " . $lname . "<br>";
echo "Email: <a href=mailto:" . $email . ">" . $email . "</a><br>";
echo "Student: " . $student;
?>
</body>
Input:
"` error reporting would catch that as a parse error. – Funk Forty Niner May 11 '15 at 02:16