php 结合mysql实现的用户注册实例
php写了一个简单的用户注册页面。本篇结合前一篇的内容,将注册页面上提交的信息post 给后面的页面register.php ,register.php将post的信息提交入库。 一、创建数据库与表结构 1、建库 mysql> create database manongjc?character set utf8; Query OK,1 row affected (0.00 sec) 上面我建了一个同我站点同名的库manongjc。 2、创建表结构 CREATE TABLE IF NOT EXISTS `tblmember` ( `id` int(11) NOT NULL AUTO_INCREMENT, `fName` varchar(30) NOT NULL, `lName` varchar(30) NOT NULL, `email` varchar(50) NOT NULL, `password` varchar(60) NOT NULL, `birthdate` text NOT NULL, `gender` varchar(20) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=10 ; 这里的字符编码我选择的是utf8,并且在该表的id值是从11开始的(前面预留了10个),数据库引擎类型用的InnoDB,具体可以根据自己的需求修改。 二、post提交php页面 向后端提交post请求的register.php代码如下: //set up mysql connection mysql_connect("localhost","root","123456") or die(mysql_error()); //select database mysql_select_db("manongjc") or die(mysql_error()); //get the value from the posted data and store it to a respected variable $fName = $_POST['fName']; $lName = $_POST['lName']; $email = $_POST['email']; $reemail = $_POST['reemail']; $password = sha1($_POST['password']); $month = $_POST['month']; $day = $_POST['day']; $year = $_POST['year']; $gender = $_POST['optionsRadios']; $birthdate = $year . '-' . $month . '-' . $day; //insert data using insert into statement $query = "INSERT INTO tblmember(id,fName,lName,email,password,birthdate,gender) VALUES (NULL,'{$fName}','{$lName}','{$email}','{$password}','{$birthdate}','{$gender}')"; //execute the query if (mysql_query($query)) { //dislay a message box that the saving is successfully save echo ""; } else die("Failed: " . mysql_error()); ?> 上面的代码使用时,数据库的用户名密码及库名根据实际情况修改。 以上是本文章的全部内容,希望对初学者有一定的用处。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |