你不能在html文件中执行php代码。所以,将form.html文件扩展名设为form.php 如果发生错误,从process.php重定向到form.php时传递一个get参数。
检查form.php中是否有get参数然后呈现消息。
if($arrmessage =="") { $student_name = $_POST['student_name']; $email = $_POST['email']; $contact_number = $_POST['contact_number']; $gender = $_POST['gender']; $interest = $_POST['interest']; $checked =""; foreach($interest as $list){$checked .= $list .",";} $DOB = $_POST['day'].'-'.$_POST['month'].'-'.$_POST['year']; $street_adress = $_POST['street_adress']; $city = $_POST['city']; $state = $_POST['state']; $country = $_POST['country']; $sql = "INSERT INTO form (student_name,email,contact_number,gender,interest,DOB,street_adress,city,state,country)VALUES('{$student_name}','{$email}','{$contact_number}','{$gender}','{$checked}','{$DOB}','{$street_adress}','{$city}','{$state}','{$country}')"; mysql_query($sql); if(mysql_insert_id() != ""){ echo "Records inserted successfully."; } header("Location:views.php"); exit; } else { header("Location:form.php?error=1&msg=$arrmessage"); }
在form.php文件中你需要检查get if $ _GET ['error']然后显示你在$ _GET ['msg']中得到的消息