本学期我正在做noobie PHP编码的事情。我有一个任务,它拥有一个php文件中的所有html。我将添加if语句,如果任何字段为空且在数字字段中输入负数时将生成错误消息。PHP无法为空字段生成错误消息
这很简单,答案最简单。没有数组或类似的东西。只要直/如果等。我也肯定这是一件非常明显和简单的事情,我只是没有得到;充其量,我是SQL以外的笨拙编码器。你可以看到我试图获得错误信息,即使它不起作用,我仍然留下这些信息。希望这会导致我有缺陷的想法朝向的地方。
<!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>
除非你正在运行一个石器时代或令人难以置信的错误配置的PHP安装启用了register_globals,你永远不会得到任何东西'$ product_description',所以你的错误信息将会被设置。 – 2014-09-05 14:55:05