<?php
header("content-type:text/html;charset=utf-8");
//1.接收数据
$username = $_POST['username'];
$password = $_POST['password'];
$repass = $_POST['repass'];
$age = $_POST['age'];
//获取当前脚本的请求时间(注册时间)
$rtime = $_SERVER['REQUEST_TIME'];
//获取客户端的IP地址(注册IP)
$rip = $_SERVER['REMOTE_ADDR'];
$rip = ip2long($rip);
//判断密码两次输入是否一致
if($password!=$repass){
exit("对不起,亲,您手又抖了吧,两次密码输入不一致,请重新输入!");
}
$password = md5($password);
//数据插入的天龙八部
//1.数据库连接
$link = mysql_connect("localhost","root","lixiaoshuai");
//2.判断错误
if(mysql_errno()){
exit("数据库连接失败:".mysql_error());
}
//3.设置字符集
mysql_set_charset("utf8");
//4.选择数据库
mysql_select_db("psd1311");
//5.准备sql语句
$sql = "insert into shop_user(username,password,age,rtime,rip) values('$username','$password',{$age},{$rtime},{$rip})";
//6.发送sql语句
$result = mysql_query($sql);
//7.处理结果
if($result && mysql_affected_rows()){
echo "恭喜您,注册成功!注册的个数:".mysql_affected_rows().";您的ID号:".mysql_insert_id();
}else{
echo "对不起,您没有注册成功!失败原因:".mysql_error();
}
//8.关闭连接
mysql_close($link);