我正在为提交的信息制作页面。当这个人没有填写一个方框(在这种情况下是名字)时,它应该改为$ okay为FALSE。现在,当我运行它时,这个代码只有一半有效 它会打印出句子,但不会将$ ok改为false。
<?php
$FirstName = $_POST['firstname'];
$LastName = $_POST['lastname'];
$Email = $_POST['email'];
$CompanyName = $_POST['companyname'];
$Description = $_POST['description'];
$okay = TRUE;
if (empty($FirstName)) {
echo '<p class="error"> Please enter first name</p>';
$okay = FALSE;
}
if ($okay = TRUE) {
echo "<p> Thank you $FirstName $LastName. We are looking foward to doing business with you. Please look for an email at $Email from
BrandingYouSmall@gmail.com for '$CompanyName' </p>";
echo "<p> Your Description: <br /> $Description </p>";
}
?>
答案 0 :(得分:4)
if($okay = TRUE){
这是一个问题。单=
是赋值的运算符。所以你告诉&#34;将$ okay设置为TRUE&#34;。但你想要检查。所以你需要使用相等运算符 - ==
。解决它:
if ($okay == true) {
或更短:
if ($okay) {