if ($name == "" || $address == "" || $phone== "" || $vertificationCode == "") {
echo '<div class="ui-poptips-cnt">资料不完整无法提交!</div>';
}elseif (!preg_match("/^[\x80-\xff]{3,30}$/",$name)) {
echo '<div class="ui-poptips-cnt">称呼请使用中文!</div>';
}elseif (($qq != '') && (!preg_match("/^[1-9][0-9]{4,10}$/",$qq))) {
echo '<div class="ui-poptips-cnt">QQ号码格式不正确!</div>';
}elseif (($wx != '') && (!preg_match("/^[a-za-z]{1}([a-za-z0-9]|[._]){3,19}$/",$wx))) {
echo '<div class="ui-poptips-cnt">微信账号格式不正确!</div>';
}elseif (!preg_match("/^1[34578]\d{9}$/",$phone)) {
echo '<div class="ui-poptips-cnt">手机号码格式不正确!</div>';
}elseif (!preg_match("/^\d{4}$/",$vertificationCode)) {
echo '<div class="ui-poptips-cnt">验证码格式不正确!</div>';
}elseif (preg_match("/<[\/\!]*?[^<>]*?/is",$message)) {
echo '<div class="ui-poptips-cnt">留言中不允许包含特殊字符!</div>';
}elseif ($vertificationCode != $_SESSION['vertiCodeS']){
echo '<div class="ui-poptips-cnt">输入的验证码有误,请确认</div>';
}elseif ($phone != $_SESSION['phone']) {
echo '<div class="ui-poptips-cnt">现手机号和原号码无法匹配!</div>';
}else{
$sql = "select * from userdata where phone='$phone' limit 1";
$result = $conn->query($sql);
$num = mysqli_fetch_assoc($result);
if ($num['phone'] == $phone) {
echo '<div class="ui-poptips-cnt">号码:'.$phone.' 已经提交过!</div>';
}else{
$time = time();
$sql = "INSERT INTO `userdata`(`name`, `address`, `qq`, `wx`, `phone`, `message`, `time`) VALUES ('$name','$address','$qq','$wx','$phone','$message','$time')";
$result = $conn->query($sql);
if ($result) {
echo '<div class="ui-poptips-cnt">提交成功!</div>';
}else {
echo '<div class="ui-poptips-cnt">提交失败!</div>';
}
}这段php代码业务逻辑还有其它优化简写方法吗?麻烦各位给点建议 谢谢
- 1 回答
- 0 关注
- 1022 浏览
添加回答
举报
0/150
提交
取消