I'm doing the noobie PHP coding thing this semester. I have an assignment which has all html in a php file. I am to add if statements which will generate error messages if any field is empty and if a negative number is entered in the numeric fields.
This is really simple, and the answer is preferably simple. No arrays or anything like that. Just straight if/else and such. I'm also positive that it's something really obvious and simple I'm just not getting; I'm a clumsy coder outside SQL, at best. You can see my attempts at getting the error message to stick, which I've left in even though it doesn't work. Hopefully that leads to where my flawed thinking is headed.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Product Discount Calculator</title>
<link rel="stylesheet" type="text/css" href="main.css" />
</head>
<body>
<div id="content">
<h1>Product Discount Calculator</h1>
<form action="display_discount.php" method="post">
<?php $error_message = " "; ?>
<div id="data">
<label>Product Description:</label>
<input type="text" name="product_description"/><br />
<?php if ( empty($product_description) ) {$error_message = 'This field cannot be blank'}; ?>
<span class="error">* <?php echo $error_message;?></span>
<label>List Price:</label>
<input type="text" name="list_price"/><br />
<label>Discount Percent:</label>
<input type="text" name="discount_percent"/>%<br />
</div>
<div id="buttons">
<label> </label>
<input type="submit" value="Calculate Discount" /><br />
</div>
</form>
</div>
</body>
</html>