Help required with HTML & PHP

My HTML page is called “hw05.html” and i need to include a link back to it on my PHP but don’t know how. Also my $cost isn’t calculating correctly

<!doctype html>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<html lang="en">
<head>
    <title> Homework 5- Pizza Order </title>
    <link rel="stylesheet" href="hw05.css">
</head>
<body>


<?
	// input
  	$name = $_POST['name'];
  	$cellnumber = $_POST['cellnumber'];
  	$small = $_POST['small'];
  	$medium = $_POST['medium'];
  	$large = $_POST['large'];
  	$pepperoni = $_POST['pepperoni'];
  	$sausage = $_POST['sausage'];
  	$mushrooms = $_POST['mushrooms'];
  	$ham = $_POST['ham'];
  	$olives = $_POST['olives'];
  	$onions = $_POST['onions'];
  	
	// process
	$count = 0;
	$cost = 0;
	if ($size == 'small')
		$cost = 5;
	if ($size == 'medium')
		$cost = 8;
	if ($size == 'large')
		$cost = 10;
	if (isset ($_POST['pepperoni'])) {
		$cost += 1.00;
		$count++;
	}
	if (isset ($_POST['sausage'])) {
		$cost += 1.50;
		$count++;
	}
	if (isset ($_POST['mushrooms'])) {
		$cost += 0.80;
		$count++;
	}
	if (isset ($_POST['ham'])) {
		$cost += 1.25;
		$count++;
	}
	if (isset ($_POST['olives'])) {
		$cost += 0.75;
		$count++;
	}
	if (isset ($_POST['onions'])) {
		$cost += 0.50;
		$count++;
	}
	
	
	// output
	print "<b> Thank you for your order $name. </b> <br />
			The cost for your $count topping pizza is: $$cost.";


?>



</body>
</html>

All you really need to do is write a regular href link to that file on your PHP file.

Hey I’m really new to this. Im taking my first “web development” course. How do I do that?

You haven’t linked your PHP file to the HTML file have you?

Welcome to the forums, @annachristianb.

When you have two very different questions like this, it is better to start two different threads, each in the appropriate section of the forums.

@spaceshiptrooper has answered the HTML question. I suggest you start a new thread in the PHP forum for your second question.

Thank you for your help. I’ll make sure I do that next time.

At the top of the page add these debug lines and the problem should be shown.

<?php 
Ini_set('display_errors', 'true');
error_reporting(-1);

?>
1 Like

OP is referencing $size which was never created. So OP will see Undefined Index error for that line. And then OP is trying to get $_POST variables on a $_GET request so even more Undefined Index errors. Not only that, the calculation is done after the logic check thus not giving the correct answer.

I think what you want is a form that can be used with the processing code. If that is the case it seems like there is much online similar to what you are doing. In particular this looked promising.

https://php.radford.edu/~astike/pizzaform.html

However, if you search the phrase on google “creating a php form for a pizza” there is a bunch of stuff. Including a youtube video for a simple pizza form.

There are also problems with processing code as spaceshiptrooper pointed out. Its a little odd for a beginner assignment to begin with the processing code than the form html. I would think it should be the other way around.

Moved to the PHP forum.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.