警報消息中的變量的警報消息,以顯示未輸入字段名稱。每當我嘗試運行代碼時,警告框都會顯示無任何消息,但是當我運行代碼時不會顯示 - 「。$ fieldname」。該消息被顯示。 我希望未輸入的字段名與消息一起顯示。試圖顯示帶有消息
if(isset($_POST['submit']))
{
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$mobile = $_POST['mobile'];
$course = $_POST['course'];
$semester = $_POST['semester'];
$DOB = $_POST['DOB'];
$gender = $_POST['sex'];
$file = $_FILES["file"]["name"];
$password = $_POST['password'];
$email_id = $_POST['email_id'];
$fields = array('firstname', 'lastname', 'mobile', 'course', 'semester', 'DOB', 'sex', 'password', 'email_id');
$error = false; //No errors yet
foreach($fields AS $fieldname)
{ //Loop trough each field
if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname]))
{
echo "<script type='text/javascript'>alert('field'.$fieldname.'not entered');</script>";
//Display error with field
$error = true; //Yup there are errors
}
}
'警報(「場‘$字段名。’沒有進入」)內' – roullie
謝謝你,它的工作 –