Blogger Information
Blog 2
fans 0
comment 0
visits 1342
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
22天作业,添加表单验证,性别部分
张云霸的博客
Original
632 people have browsed it



<?php
header("Content-type: text/html; charset=utf-8");

$name = isset($_REQUEST['name']) ? $_REQUEST['name'] : null;

if (empty($name)) {  //现在的返回结果就正确了
   echo '<script>alert("您没有输入用户名~~")</script>';
} else {
   echo '<script>alert("您的用户名是:'.$name.'")</script>';
}
//验证邮箱
$email = isset($_REQUEST['email']) ? $_REQUEST['email'] : null;
if (empty($email)) {  //现在的返回结果就正确了
   echo '<script>alert("您没有输入邮箱~~")</script>';
} else {
   echo '<script>alert("您的邮箱是:'.$email.'")</script>';
}

//验证性别
$gender = isset($_REQUEST['gender']) ? $_REQUEST['gender'] : null;
//如果用户没有选择,那么会返回null
if (is_null($gender)) {
   echo '<script>alert("您没有选择性别~~")</script>';
} else {
   if ($gender == 'male') {
       echo '<script>alert("晚上好,小帅哥~~")</script>';
   } elseif ($gender == 'female') {
       echo '<script>alert("晚上好,小美女~~")</script>';
   } elseif ($gender == 'shemale') {
       echo '<script>alert("我懂你的痛,好好休息,保重~~");</script>';
   } else {
       echo '<script>alert("选择有误~~");</script>';
   }


}
//年纪验证

$age = isset($_REQUEST['age']) ? $_REQUEST['age'] : null;
if (is_null($age)) {
   echo '<script>alert("您没有选择年纪~~")</script>';
} else {
   if ($age == '1') {
       echo '<script>alert("晚上好,年轻人~~")</script>';
   } elseif ($age == '2') {
       echo '<script>alert("晚上好,大叔~~")</script>';
   } elseif ($age == '3') {
       echo '<script>alert("好好休息,保重~~");</script>';
   } else {
       echo '<script>alert("选择有误~~");</script>';
   }
//验证年龄与备注为作业

   if ($name && $email & $gender) {
       echo '<script>alert("验证通过~~");location.href="success.php";</script>';
   } else {
       echo '<script>alert("验证失败,请检查~~");location.href="demo5.php"</script>';
   }


}

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments