reg.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="dist/css/bootstrap.css"> <script srt="dist/js/bootstrap.js"></script> <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> <title>网站注册</title> </head> <body> <div class="container"> <div class="row"> <div class="col-md-3"></div> <div class="col-md-6 "> <h3 class="text-center">用户注册</h3> <form class="form-horizontal" method="post" action="check.php"> <div class="form-group"> <label for="inputEmail3" class="col-sm-2 control-label">用户名</label> <div class="col-sm-10"> <input type="text" name="name" placeholder="用户名"> </div> </div> <div class="form-group"> <label for="inputPassword3" class="col-sm-2 control-label">密码</label> <div class="col-sm-10"> <input type="password" name="password" placeholder="密码"> </div> </div> <div class="form-group"> <label for="inputPassword3" class="col-sm-2 control-label">性别</label> <div class="radio"> <label> <input type="radio" name="sex" value="male" checked> 男性 </label> <label> <input type="radio" name="sex" value="female"> 女性 </label> <label> <input type="radio" name="sex" value="shemale" > 未知 </label> </div> </div> <div class="form-group"> <label for="inputPassword3" class="col-sm-2 control-label">年龄</label> <div class="col-sm-10"> <select name="age"> <option value="option1">10-20岁</option> <option value="option2">20-30岁</option> <option value="option3">30-40岁</option> </select> </div> </div> <div class="form-group"> <label for="inputPassword3" class="col-sm-2 control-label">备注</label> <div class="col-sm-10"> <textarea rows="3" name="text"></textarea> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <div class="checkbox"> <label> <input type="checkbox"> 记住我 </label> </div> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default" name="submit">注册</button> </div> </div> </form> </div> <div class="col-md-3"></div> </div> </div> </body> </html>
check.php
<?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>'; } $password=isset($_REQUEST['password']) ? $_REQUEST['password'] : null; if(empty($password)){ echo '<script>alert("您没有输入密码,请输入密码");)</script>'; }else{ echo '<script>alert("请牢记您的密码")</script>'; } $sex = $_REQUEST['sex']; if($sex == 'male'){ echo '<script>alert("您的性别是'.$sex.'")</script>'; }elseif ($sex == 'female'){ echo '<script>alert("您的性别是'.$sex.'")</script>'; }elseif ($sex == 'shemale'){ echo '<script>alert("您的性别是'.$sex.'")</script>'; } $age = $_REQUEST['age']; switch ($_REQUEST['age']){ case 'option1': echo '<script>alert("您的年龄范围是10-20岁")</script>'; break; case 'option2': echo '<script>alert("您的年龄范围是20-30岁")</script>'; break; case 'option3': echo '<script>alert("您的年龄范围是30-40岁")</script>'; break; default: echo '<script>alert("您的年龄范围是")</script>'; } $text=isset($_REQUEST['text']) ? $_REQUEST['text'] : null; if(empty($age)){ echo '<script>alert("请输入备注");</script>'; }else{ echo '<script>alert("您的备注是'.$text.'")</script>'; }