<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
$Fname = $_POST["Fname"];
$Lname = $_POST["Lname"];
$email = $_POST["email"];
$address1 = $_POST["address1"];
$address2 = $_POST["address2"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip_code = $_POST["zip"];
$phone = $_POST["phone"];
$distance = $_POST["distance"];
//form php validation error massage for blank fields
if($Fname == "" || $Lname == "" || $email == "" || $address1 == "" || $city == "" || $state == "" || $zip_code == "" || $phone == ""){
$msg = "<p class='error'>The required fields cannot be blank</p>"
;
}
if(!filter_var($email, FILTER_VALIDATE_EMAIL) && !isset($msg)){ //email validation
$msg = "<p class='error'>You must place a real email address</p>";
}else{
require_once("inc/admin_login.php"); //log in database file
$query = "INSERT INTO runner(fname,lname,email,address1,address2,city,state,postcode,phone,distance) VALUES('$Fname','$Lname','$email','$address1','$address2','$city','$state','$zip_code','$phone','$distance')";
$result=mysqli_query($con,$query);
if($result){ //if successfull logining in to database message
$msg = "<h2 class='notice'>Thank You For Signing Up</h2>";
}else{
$error_message = mysqli_error($con);
$result = "There was an error: $error_message";
exit($result);
}// end if
}//end else
header("Location:signup.php?status=thankyou"); //redicrects you when comments are entered in correctly
}// end of main 1st if
$pageTitle="Sign Up";
include("inc/header.php");
include("inc/navigation.php");
?>
<div class="signupWrapper">
<h1>Sign up to run</h1>
<?php if(isset($msg)){ //where blank error message will display
echo $msg;
}if(isset($_GET['status']) && $_GET['status'] == "thankyou"){ // msg that displays on the redirect page if comments are entered correctly
echo "<p class='notice'>Thank you for submitting your comment</p>";
}else{
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" id="signUpForm" name="signUpForm" title="Sign To Race Form">
<table class="signUp">
<tr>
<th>
<label for="Fname">First Name:</label>
</th>
<td>
<input type="text" id="Fname" name="Fname"></input>
</td>
</tr>
<tr>
<th>
<label for="Lname">Last Name:</label>
</th>
<td>
<input type="text" id="Lname" name="Lname"></input>
</td>
</tr>
<tr>
<th>
<label for="email">Email:</label>
</th>
<td>
<input type="email" id="email" name="email"></input>
</td>
</tr>
<tr>
<th>
<label for="address1">Address 1:</label>
</th>
<td>
<input type="text" id="address1" name="address1"></input>
</td>
</tr>
<tr>
<th>
<label for="address2">Address 2:</label>
</th>
<td>
<input type="text" id="address2" name="address2"></input>
</td>
</tr>
<tr>
<th>
<label for="city">City:</label>
</th>
<td>
<input type="text" id="city" name="city"></input>
</td>
</tr>
<tr>
<th>
<label for="state">State:</label>
</th>
<td>
<input type="text" id="state" name="state"></input>
</td>
</tr>
<tr>
<th>
<label for="zip">Zip Code:</label>
</th>
<td>
<input type="text" id="zip" name="zip"></input>
</td>
</tr>
<tr>
<th>
<label for="zip">Phone:</label>
</th>
<td>
<input type="text" id="phone" name="phone" title="enter phone number"></input>
</td>
</tr>
<tr>
<th>
<label for="">Distance:</label>
</th>
<td>
<fieldset>
<label for="distance1">1 Mile</label><input type="radio" id="distance1" name="distance" value="1mile" ></input>
<label for="distance2">5K</label><input type="radio" id="distance2" name="distance" value="5K" checked></input>
<label for="distance3">10K</label> <input type="radio" id="distance3" name="distance" value="10K" ></input>
</fieldset>
</td>
</tr>
<tr>
<th>
</th>
<td>
<label for=""></label><input type="submit" id="submitForm" name="submitForm" value="Submit" title="submit button"></input>
<label for=""></label><input type="reset" id="clear" name="clear" value="Clear" title="clear button" ></input>
</td>
</tr>
</table>
</form>
<?php }?> <!-- ends the else statement above in the start of the form, to only show the thank you message/ thank redirect page if
comments are entered in correctly -->
</div>
(PHP)从字段为空白并且关闭JavaScript时,提交而不是显示错误消息
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- douguaidian8021 2018-03-05 08:21关注
just check it
if($_SERVER['REQUEST_METHOD']=='POST') { $Fname = $_POST['fnm']; $Lname = $_POST['lnm']; $email = $_POST['email']; if($Fname == "" || $Lname == "" ) { $msg = "<p class='error'>The required fields cannot be blank</p>" ; } else if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { $msg = "<p class='error'>You must place a real email address</p>"; } else { $msg = "<p class='error'>Form submition gose here</p>"; } echo $msg; }
解决 无用评论 打赏 举报
悬赏问题
- ¥20 cad图纸,chx-3六轴码垛机器人
- ¥15 移动摄像头专网需要解vlan
- ¥15 对于这个问题的算法代码
- ¥20 access多表提取相同字段数据并合并
- ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
- ¥20 Java-Oj-桌布的计算
- ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
- ¥20 有人知道这种图怎么画吗?
- ¥15 pyqt6如何引用qrc文件加载里面的的资源
- ¥15 安卓JNI项目使用lua上的问题