当前位置:主页 > 网络编程 > PHP教程 >

php中传统验证与thinkphp框架

时间:2017-11-22 | 栏目:PHP教程 | 点击:

PHP(超文本预处理器)可用于小型网站的搭建,当用户需要注册登录是,需要与后台数据库进行匹配合格才能注册和登录,传统的方式步骤繁多,需要先连接数据库再用sql语句进行插入。

<?php
header("Content-type: text/html; charset=utf-8");
$conn =mysqli_connect("localhost","root","");
if (!$conn){
   echo "<script>alert('连接失败!');history.go(-1);</script>";
  } 
mysqli_select_db($conn,"liuyanban");
mysqli_query($conn,'SET NAMES utf8');
$password=$_POST['password'];
$username=$_POST['username'];
$face="yellow.png";
$result=mysqli_query($conn,"SELECT username from user1 where username = '$username'"); 
$a=mysqli_num_rows($result);
if($a)
{    
   echo "<script language=javascript>alert('用户名已存在!');location.href='reg.html'</script>";
}
else
{   
    $sql = mysqli_query($conn,"INSERT INTO user1(username,password,face)VALUES('1' ,'2','yellow.png')");
   if($sql)
   {
      echo "<script language=javascript>alert('注册成功!');location.href='login.html'</script>";
   }
   else
   {
      echo "<script>alert('注册失败!');location.href='reg.html'</script>";
   }
}
?>

您可能感兴趣的文章:

相关文章