0

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.

18
  • 2
    If you get http 500 for your php page, your php has error, set your php.ini to display error message in order to help you debug your code. Commented May 1, 2017 at 22:13
  • 1
    You should be able to check your PHP error logs to find out what the error is. Also, since it is a 500 error, you should be able to run php php/process.php from the command line and it will tell you what your mistakes are. Commented May 1, 2017 at 22:15
  • 1
    @kojow7 No, I'm doing great thanks. I hope you're the same :-) Commented May 1, 2017 at 22:33
  • 1
    Great to hear...and I am. :) Commented May 1, 2017 at 22:34
  • 1
    Group hug!! Commented May 1, 2017 at 22:35

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I repeat my quiet link to this post but am happy to provide you with some much needed +10 :-D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.