I have some very simple PHP code that I'm using to confirm input from a form.
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Unit 7 - Homework 5</title>
</head>
<body>
<h1>Contact us</h1>
<table>
<form method="POST" action="script.php">
<tr>
<td>First Name:</td>
<td><input type="text" name="First Name" id="fname"></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="Last Name" id="lname"></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input type="text" name="E-mail" id="email"></td>
</tr>
<tr>
<td>Comments</td>
<td><textarea rows="10" cols="40"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Contact"> <input type="reset"></td>
</tr>
</form>
</table>
</body>
</html>
PHP
<?php print "<!DOCTYPE html>
<html lang=\"en\">
<head>
<title>Form Confirmation</title>
</head>
<body>
<h1>Congratulations, registration done!</h1>";
$message = ";
foreach ($_POST as $key => $value) {
$message .= $key . ":" .$value. "<br>\r\n";
}
print $message;
print "<br>
<br>
<br>
<br>
<br>
<br>
<form action=\"#\">
<input type=\"button\" value=\"Back\" onclick=\"javascript:history.go(-1)\" />
</form>
</body>
</html>"
?>
The PHP code keeps producing an error.
Parse error: syntax error, unexpected ':' in <PHP path goes here> on line 10
I'm not sure what I'm doing wrong, although I feel I might have forgotten a semicolon.
your only mistake is that you have put the text thjat you wanted php to print in double quotes, this means that php will evaluate it and see if it needs to process something with it. Instead you should have put it in single quote like this: ... ':' ...
Anything quoted in single quotes will be printed as-it-is, character by character. Anything in double quotes will be evaluated.