Reputation: 57
I am sure this is very simple to many of you!! I am trying to learn basic HTML / PHP form processing. The site is hosted on a local Apache server. I have had PHP working correctly and am happy that the server is working fine.
I have two files, one is settings.html, where the user has a form of 3 elements which they can enter some float values into (humidity, temperature and light tolerances). The submit button triggers a separate file called process.php which should display the three values. The code is as follows:
settings.html:
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<meta http-equiv="refresh" content="179" >
<title>Sparks - Settings</title>
<link rel="stylesheet" type="text/css" href="css/default.css">
</head>
<body>
<div id="logo">
<img style="width: 335px; height: 142px;" alt="ESP8266 Logo" src="images\imgESP8266.png">
</div>
<br>
<form method="post" action="php/process.php">
Humidity Tolerance : <input type="float" name="humTolerance" placeholder="Enter %" /><br />
Temperature Tolerance : <input type="float" name="tempTolerance" placeholder="Enter %" /><br />
Light Tolerance : <input type="float" name="lightTolerance" placeholder="Enter %" /><br />
<input type="submit" value="Submit" />
</form>
</body>
<html>
php/process.php:
<?php //process.php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$humTolerance = $_POST["humTolerance"];
$tempTolerance = $_POST["tempTolerance"];
$lightTolerance = $_POST["lightTolerance"];
}
echo <<<_END
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<meta http-equiv="refresh" content="179" >
<title>Sparks - Settings</title>
<link rel="stylesheet" type="text/css" href="css/default.css">
</head>
<body>
humTolerance is: $humTolerance<br>
tempTolerance is: $tempTolerance<br>
lightTolerance is: $lightTolerance<br>
</body>
</html>
_END;
?>
This is producing the HTTP ERROR 500 and I can't see why. Please can I have some help? Thanks.
Upvotes: 0
Views: 197
Reputation: 74217
As I said in comments:
"the (first) problem is in your heredoc closing identifier it contains spaces before it."
and
"the second one:
type="float"
isn't a valid type for an input"
You need to replace those input types with ones that are valid.
Note that not all browsers support certain HTML5 attributes, see the above as a reference.
So use type="number"
or type="text"
.
PHP with spaces removed before the closing heredoc identifier.
<?php //process.php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$humTolerance = $_POST["humTolerance"];
$tempTolerance = $_POST["tempTolerance"];
$lightTolerance = $_POST["lightTolerance"];
}
echo <<<_END
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<meta http-equiv="refresh" content="179" >
<title>Sparks - Settings</title>
<link rel="stylesheet" type="text/css" href="css/default.css">
</head>
<body>
humTolerance is: $humTolerance<br>
tempTolerance is: $tempTolerance<br>
lightTolerance is: $lightTolerance<br>
</body>
</html>
_END;
?>
Use PHP's error reporting also:
If you don't have access to logs, then set that to catch and display.
Upvotes: 3