[英]Echo Javascript with IF-ELSE in PHP
I'm new to PHP and I have a problem about my Javascript is not working for now. 我是PHP新手,我有一个问题,我的Javascript目前无法正常工作。
Here is my codes so far 到目前为止,这是我的代码
<?php
$email = $_POST["App_Email"];
$password = $_POST["App_Password"];
$name = $_POST["App_Name"];
$lName = $_POST["App_LName"];
$gender = $_POST["App_Gender"];
$birthday = $_POST["App_Birthday"];
$nationality = $_POST["App_Nationality"];
$telNumber = $_POST["App_Tel"];
$address = $_POST["App_Address"];
$district = $_POST["App_District"];
$city = $_POST["App_City"];
$zipcode = $_POST["App_Zipcode"];
$repass = $_POST["RePassword"];
$message = "";
if($email == "" or $password == "" or $repass == "" or $name == "" or $lName == "" or $birthday == "" or $nationality == "" or $telNumber == "" or $address == "" or $district == "" or $city == "" or $zipcode == "" ){
$message = "FILL ALL";
}
elseif($repass != $password){
$message = "NOT MATCH";
}
echo '<script type="text/javascript">';
if($message == "FILL ALL"){
echo 'alert("Please fill in all provided field(s).")';
echo 'location.href = "registration.php"';
return;
}
else if($message == "NOT MATCH"){
echo 'alert("Your confirmation password is not match with your password.")';
echo 'location.href = "registration.php"';
return;
}
echo '</script>';
?>
<br><br>
<form method="POST" action="confirm-registration.php">
Name : <?php echo $_POST["App_Name"]; ?><br><br>
Lastname : <?php echo $_POST["App_LName"]; ?><br><br>
Gender : <?php echo $_POST["App_Gender"]; ?><br><br>
Date of birth : <?php echo $_POST["App_Birthday"]; ?> <br><br>
Nationality : <?php echo $_POST["App_Nationality"]; ?><br><br>
Tel. : <?php echo $_POST["App_Tel"]; ?><br><br>
Address : <?php echo $_POST["App_Address"]; ?><br><br>
District : <?php echo $_POST["App_District"]; ?><br><br>
City : <?php echo $_POST["App_City"]; ?><br><br>
Zipcode : <?php echo $_POST["App_Zipcode"]; ?><br><br>
<input type='hidden' name='App_Email' value='<?=$email?>'>
<input type='hidden' name='App_Password' value='<?=$password?>'>
<input type='hidden' name='App_Name' value='<?=$name?>'>
<input type='hidden' name='App_LName' value='<?=$lName?>'>
<input type='hidden' name='App_Gender' value='<?=$gender?>'>
<input type='hidden' name='App_Birthday' value='<?=$birthday?>'>
<input type='hidden' name='App_Nationality' value='<?=$nationality?>'>
<input type='hidden' name='App_Tel' value='<?=$telNumber?>'>
<input type='hidden' name='App_Address' value='<?=$address?>'>
<input type='hidden' name='App_District' value='<?=$district?>'>
<input type='hidden' name='App_City' value='<?=$city?>'>
<input type='hidden' name='App_Zipcode' value='<?=$zipcode?>'>
<button onClick="history.back()";> Back </button> <input type="submit" name="submit" value="Confirm">
</form>
From the codes above, my result in this page is just a plain white page. 从上面的代码中,我在此页面中的结果只是一个纯白页面。
When I tried to test the not completed the form case and password is not matched. 当我试图测试未完成的表格案例和密码不匹配时。 But no alert is pop-up.
但是没有弹出警报。 Even all fields from the form page is inserted, this page stills plain white.
即使插入了表单页面中的所有字段,此页面仍为纯白色。
Please help. 请帮忙。
Various problems in your code: 代码中的各种问题:
isset()
. isset()
。 Turn on your error reporting, you will find numerous Notice: Undefined index
errors Notice: Undefined index
错误 return
in if
? return
的if
? Is it a function? Missing ;
失踪
;
in your Javascript: 在你的Javascript中:
if($message == "FILL ALL"){ echo 'alert("Please fill in all provided field(s).");'; echo 'location.href = "registration.php";'; } else if($message == "NOT MATCH"){ echo 'alert("Your confirmation password is not match with your password.");'; echo 'location.href = "registration.php";'; }
All your HTML fields are hidden
, where does the user enter values? 您的所有HTML字段都是
hidden
,用户在哪里输入值?
Use ; 采用 ; inside echo statements
内部回声声明
if($message == "FILL ALL"){
echo 'alert("Please fill in all provided field(s).");';
echo 'location.href = "registration.php";';
}
else if($message == "NOT MATCH"){
echo 'alert("Your confirmation password is not match with your password.");';
echo 'location.href = "registration.php";';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.