创建数据库,库名为考生姓名拼音的缩写,例如考生姓名为张三,则数据库名为:zs,
(1)创建一个是用户表,名称为user, 用户表字段包括:
user_id,user_name,pwd,email分别代表用户id,用户姓名,密码,邮箱。
要求:提交建表SQL语句。
(2)编程实现用户注册界面register.php,如下图。
如用户名已注册,仍停留在注册页面,界面如下图。
登录成功后用cookie记录用户id和用户名.登录成功后转入主页面
(3)编程实现主页面index.php,如用户注册成功则转入主界面如下图。
代码如下:
register.php
<?php /** * Created by PhpStorm. * User: lgy * Date: 2017/4/3 * Time: 21:46 */ if($_SERVER['REQUEST_METHOD']=='POST') { $conn=new mysqli("localhost","root","root","lgy"); $conn->query("set names utf-8"); if(!$conn) { die("连接错误:".msqli_connect_error()); } else{ $name=$_POST["name"]; $pwd=$_POST["pwd"]; $email=$_POST["email"]; $sql="select user_name from user where user_name='".$name."'"; $result=$conn->query($sql); if($result->num_rows>0) { echo "用户名已存在"; } else{ $sql="insert into user set user_name='$name',email='$email',pwd='$pwd'"; $results=$conn->query($sql); if($results>0) { setcookie("name",$name,time()+60*60*1); header("Location:index.php"); } } } } ?> <form action="" method="POST"> <table> <tr> <td> <label>用户名:</label> <input type="text" value="" name="name"> </td> </tr> <tr> <td> <label>密 码:</label> <input type="password" value="" name="pwd"> </td> </tr> <tr> <td> <label>E-Mail: </label> <input type="text" value="" name="email"> </td> </tr> <tr> <td> <input type="submit" value="提交"> </td> </tr> </table> </form>
index.php
<?php /** * Created by PhpStorm. * User: lgy * Date: 2017/4/3 * Time: 21:45 */ if($_COOKIE ["name"]){ $val=$_COOKIE ["name"]; echo $val.",欢迎来到php100首页"; } ?>
数据库文件:
# Host: localhost (Version: 5.5.53) # Date: 2017-04-16 21:52:05 # Generator: MySQL-Front 5.3 (Build 4.234) /*!40101 SET NAMES utf8 */; # # Structure for table "user" # DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `user_name` varchar(255) DEFAULT NULL, `pwd` varchar(255) DEFAULT NULL, `email` varchar(255) DEFAULT NULL, PRIMARY KEY (`user_id`) ) ENGINE=MyISAM AUTO_INCREMENT=19 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; # # Data for table "user" # /*!40000 ALTER TABLE `user` DISABLE KEYS */; INSERT INTO `user` VALUES (8,'1','1','1'),(9,'2','2','2'); /*!40000 ALTER TABLE `user` ENABLE KEYS */;