I bought the book "PHP 5/mySQL Programming for the Absolute Beginner."
So far I have been pleased with the book, but am stuck on a lesson and can't get past it, because the code given is either not correct(I did find an error in another lesson) or my webserver won't allow it.
I am sure there are many ways to write this particular code, but I just want the fix for this one as each lesson builds on the next. If someone could help me out that would be great! This lesson is about getting values from checkboxes using an if statement. (Please don't tell me about functions & arrays as that will be in upcoming lessons.)
This is the HTML page called
checkDemo.html:
<html>
<head>
<title>CHECK DEMO</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<h1>Check Demo </h1>
<h3>Demonstrates checkboxes</h3>
<h3>What would you like with your order?<br>
</h3>
<form action = "checkdemo.php">
<ul>
<li>
<p>
<input type="checkbox" name="chkFries" value="1.00">
Fries</p>
</li>
<li>
<p>
<input type="checkbox" name="chkSoda" value=".85">
Soda</p>
</li>
<p>
<li>
<input type="checkbox" name="chkShake" value="1.30">
Shake</li>
<p>
<li>
<input type="checkbox" name="chkKetchup" value=".05">
Ketchup</li>
</ul>
<p>
<input type="submit">
</form>
</body>
</html>
----------------------------------------------------------------------------
This is the PHP page called checkDemo.php:
<html>
<head>
<title>CHECK DEMO</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<h1>Check Demo </h1>
<h3>Demonstrates reading checkboxes</h3>
<?
print <<<HERE
chkFries : $chkFries <br>
chkSoda : $chkSoda <br>
chkShake : $chkShake <br>
chkKetchup : $chkKetchup <br>
<hr>
HERE;
$total = 0;
if (!empty($chkFries)){
print ("You chose Fries<br> \n");
$total = $total + $chkFries;
} // end if
if (!empty($chkSoda)){
print ("You chose Soda<br> \n");
$total = $total + $chkSoda;
} // end if
if (!empty($chkShake)){
print ("You chose Shake<br> \n");
$total = $total + $chkShake;
} // end if
if (!empty($chkKetchup)){
print ("You chose Ketchup<br> \n");
$total = $total + $chkKetchup;
} // end if
print "The total cost is \$$total \n";
?>
</body>
</html>
For some reason it will print the checkbox names, but no values.
Please help! Thanks!