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.

Edward Hammock
  • 57
  • 3
  • 12
  • the (first) problem is in your heredoc closing identifier http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc it contains spaces before it. – Funk Forty Niner May 01 '17 at 22:10
  • the second one: `type="float"` isn't a valid type for an input https://developer.mozilla.org/en/docs/Web/HTML/Element/input --- http://html5doctor.com/html5-forms-input-types/ --- https://www.w3.org/wiki/HTML5_form_additions – Funk Forty Niner May 01 '17 at 22:11
  • 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. – Nick Li May 01 '17 at 22:13
  • I'm surprised both my 2 first comments didn't receive upvotes; just the last one *lol* so yeah; we know if failed and that 500's a server error. – Funk Forty Niner May 01 '17 at 22:14
  • 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. – kojow7 May 01 '17 at 22:15
  • **[This topic](http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display)** should help you a lot. Good luck in your adventures `:-)` – Martin May 01 '17 at 22:21
  • @Fred-ii- I think the reason is that he needs to learn how to track down what the actual error message says. He is only seeing the HTTP status code 500 but not the actual PHP error. Regardless, you are correct with your first comment assuming the indentation mistake isn't just a pasting issue into SO. Your second comment is also correct, but would not produce a 500 error. – kojow7 May 01 '17 at 22:21
  • @kojow7 the 500's from the heredoc; I'm almost hesitant to press on "Post your answer" at this point. and the input's are wrong. There are no "float" types in HTML5 or any other inputs from previous HTML releases. – Funk Forty Niner May 01 '17 at 22:22
  • I swear; if anybody pops an answer based on (vampire's) my comments and solves it, I'll be submitting mine with timestamps from my comments. – Funk Forty Niner May 01 '17 at 22:25
  • @kojow7 *"I think the reason is that he needs to learn how to track down what the actual error message says."* - In other words; leave the question and let it not be answered/closed/marked as solved; is that what you're saying? – Funk Forty Niner May 01 '17 at 22:29
  • @Fred-ii- well if you don't submit your comments as an answer right now, you've only got yourself to blame... *rolls up sleeves, prepares mouse for copy/paste extravaganza* – Martin May 01 '17 at 22:29
  • @Martin as I did before the vampires step in. Let's see what comes of it. – Funk Forty Niner May 01 '17 at 22:31
  • @Fred-ii- Are you having a bad day today? Or is it just my misperception? – kojow7 May 01 '17 at 22:33
  • 1
    @kojow7 No, I'm doing great thanks. I hope you're the same :-) – Funk Forty Niner May 01 '17 at 22:33
  • 1
    Great to hear...and I am. :) – kojow7 May 01 '17 at 22:34
  • 1
    [Group hug!!](https://groupmissiontrips.com/media/84996/p_grouphugs-min.jpg) – Martin May 01 '17 at 22:35
  • Lol... what's with all the hate in here. IMO, if someone posted saying "the problem I had is error 500", one is either lazy or really new to the language. Posting solution directly without guiding them to tackle the problem with general technique first is not being beneficial to OP – Nick Li May 01 '17 at 23:59
  • 1
    @NickLi hate? These comments don't appear to hate..... ? – Martin May 02 '17 at 08:16

1 Answers1

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.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • 1
    I repeat my quiet link to **[this post](http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display)** but am happy to provide you with some much needed +10 `:-D` – Martin May 01 '17 at 22:33