PHP实现登录注册

HTML表单


   

登录

//取出表单提交的账号和密码
$username = $_POST['username'];
$password = $_POST['password'];
//要查询登录的账号密码SQL语句
$sql = "select username,password from user where '$username'";
//执行SQL语句
$result = mysql_query($sql);
//把取到的SQL放入数组内,便于输出
$row = mysql_fetch_array($result);
echo $row['password'];

注册

$username = $_POST['username'];
$password = MD5($_POST['password']);//密码,带MD5加密
$number = 0;
$regtime = date("Y-m-d H:m:s");//获取当前时间
$ip = $_SERVER['REMOTE_ADDR'];//获取IP
$frozen = 1;
//SQL语句
$sql = "insert into user(username,password,number,regtime,ip,frozen) values('$username','$password','$number','$regtime','$ip','$frozen')";
$que = mysql_query($sql);
if($que){
   echo "添加正确";
}else{
   echo "添加错误";
}

你可能感兴趣的:(PHP实现登录注册)