Reputation: 2641
I am new to PHP and I was making this form and I wanted to print some data but it is not displaying. What is wrong with it? Here's the code:
<form name="input" action="check.php" method="get">
Unit number:
<input type="number" name="unit" />
<input type="submit" value="Submit" />
</form>
<table>
<tr><td class="check-table">
<?php
if($_GET[unit] = null) $output="<p>Please Enter A Unit Number</p>";
echo $output;
?>
</td></tr></table>
Please Help?
Upvotes: 0
Views: 156
Reputation: 254886
The better way would be:
if (empty($_GET['unit'])) {
$output="<p>Please Enter A Unit Number</p>";
echo $output;
}
The reasons:
'
quotes for array key name$output
variable only if it is necessary. And in your case - you output it even if it doesn't exist==
(comparison operator) and =
(assignment operator)Upvotes: 4
Reputation: 23297
I think you missed the single quotes in the $_GET['unit']
<?php
if($_GET['unit'] = null) $output="<p>Please Enter A Unit Number</p>";
echo $output;
?>
Upvotes: 2