在以下PHP代码中,如果变量$emptyfields
为空,我试图使true
成为$name
。
<? php
/* Gathering Data*/
$namme = $_POST['objectname'];
$species = $_POST['species'];
$power = $_POST['power'];
$properties = $_POST['properties'];
/*Writing Data to File
$filename = $DOCUMENT_ROOT.'Galaxy/data/'.'characters.txt';
$fp = fopen($filename, 'a');
$looper =1; */
$emptyfields = false;
if (empty($name)) {
print '$name';
$emptyfields= true;
}
if (!$emptyfields) {
print '<p> Character Added! </p>
Your characer with the following details has been successfully added. <br> <br>
Details: <br>';
print '<table> <tr> <td> <b> Name: </b> </td> <td> '.$namme.
'</td> </tr>';
print '<tr> <td><b> Species: </b></td> <td>'.$species.
'</td></tr>';
print '<tr> <td> <b> Power: </b></td><td> '.$power.
'</td> </tr>';
print '<tr> <td> <b> Properties: </b></td> <td> <textarea disabled="true">'.$properties.
'</textarea></td> </tr></table>';
} else {
print '<p> Character Not Added! </p>
Your characer with the following details could not be added due to empty fields. <br> <br>';
}
?>
上面的代码已经习惯了。但不知何故,即使变量$name
不为空,变量$emptyfields
也会变为true
。如何防止?
答案 0 :(得分:2)
$namme
!= $name
您使用了
$namme = $_POST['objectname'];
将其更改为
$name = $_POST['objectname'];
^
答案 1 :(得分:0)
您的情况很好,您只是输入错字错误,只需更改此内容:
<强> PHP 强>
$namme = $_POST['objectname'];
用这个
$name = $_POST['objectname'];