-1
首先,我是編碼和PHP的新手,我試圖創建一個用戶可以編輯其用戶配置文件的配置文件頁面。PHP在if語句中嵌套elseif語句
表單已創建,但我無法確保填寫正確的字段。從我學到的東西和我的腦海中,在「if」語句中嵌套「elseif」語句將是完成我在尋找的最合乎邏輯的方式,但顯然有些東西無法正常工作,因爲當我刷新時頁面被破壞。任何幫助將不勝感激。
if (isset($_POST['btn-submit'])){
if($firstName == NULL) {
$msg = "<div class='alert alert-danger'><button class='close' data-dismiss='alert'>×</button> Please enter your first name to continue!</div>";
}
elseif ($lastName == NULL){
$msg = "<div class='alert alert-danger'><button class='close' data-dismiss='alert'>×</button> Please enter your last name to continue!</div>";
}
elseif ($txtuname == NULL){
$msg = "<div class='alert alert-danger'><button class='close' data-dismiss='alert'>×</button> Please enter your username to continue!</div>";
}
elseif ($txtemail == NULL){
$msg = "<div class='alert alert-danger'><button class='close' data-dismiss='alert'>×</button> Please enter your email to continue!</div>";
}
elseif ($busName == NULL) {
$msg = "<div class='alert alert-danger'><button class='close' data-dismiss='alert'>×</button> Please enter your business name to continue!</div>";
}
elseif ($busEmail == NULL) {
$msg = "<div class='alert alert-danger'><button class='close' data-dismiss='alert'>×</button> Please enter your business email to continue!</div>";
}
$firstName = trim($_POST['fname']);
$lastName = trim($_POST['lname']);
$txtuname = trim($_POST['uname']);
$txtemail = trim($_POST['email']);
$busName = trim($_POST['busname']);
$busEmail = trim($_POST['busemail']);
$busAddress = trim($_POST['busaddress']);
$busSuite = trim($_POST['bussuite']);
$busCity = trim($_POST['buscity']);
$busState = trim($_POST['busstate']);
$busZip = trim($_POST['buszip']);
$msg = "<div class='alert alert-success'><button class='close' data-dismiss='alert'>×</button> You are finally on the right path!</div>";
}
else {
$msg = "<div class='alert alert-danger'><button class='close' data-dismiss='alert'>×</button> Something is really screwed up!</div>";
}
你是什麼意思「的頁面被打破,當我刷新」?現在,如果'isset($ _ POST ['btn-submit'])'爲''',$ msg將始終有最後一個值。您將覆蓋它,因此您在if/elseif鏈上分配的值不會保持不變。此外,您在分配變量之前正在執行這些檢查。 – ishegg
我在瀏覽器中收到「此頁面無法正常工作」錯誤。 – user2507414