Debugging: PHP

Debugging: PHP


Example #1:

Review the HTML and PHP program below.

image of php file with errors in it


It has one syntax error on it shown in the screenshot below.

image of php file with errors in it


What line number is the error on and what is the occur?

After you think you have identified it, click below to check yhou answer.

 



Example #2:

image of php file with errors in it

This file has three syntax errors in it:

  • a comma is missing before 0,6) on line 13. It should be INT),0,6);
  • a semi-colon ; is missing on the end of line 21
  • the else statement on line 22 should not have any other text on that line (just else)

The code should look like this:



	<h1>Temperature Analyser</h1>

	<?php
		$f = substr(filter_var($_GET['f'], FILTER_SANITIZE_NUMBER_INT),0,6);
		if ($f >= 1945)
			echo "<p>Gold, Magnesium, and Bronze melt at $f degrees fahrenheit and above.</p>";
		elseif ($f >= 1218)
			echo "<p>Aluminum melts at $f degrees fahrenheit (any fahrenheit 1218 degrees or higher).</p>";
		elseif ($f >= 212)
			echo "<p>Water boils at $f degrees fahrenheit (any fahrenheit 212 degrees or higher).</p>";
		elseif ($f >= 32)
			echo "<p>$f degrees fahrenheit above freezing.</p>";
		else
			echo "<p>Water freezes at $f degrees fahrenheit (any fahrenheit below 32 degrees).</p>";
	?>