php与mysql注册页面成品

使用WAMP服务器环境,在www目录下建立webtest文件夹,通过Hbuilder X创建conn.php文件,开始实现PHP连接MySQL的注册功能。
摘要由CSDN通过智能技术生成

在wampserve文件夹中的www文件夹中创建webtest文件夹

用Hbuilder X打开

新建conn.php文件

<?php 
$servername="localhost";
$username="root";
$password="";
$dbname="d1";
//创建连接
$conn = new mysqli($servername,$username,$password,$dbname);
//检测链接
if($conn->connect_error){
	die("链接失败".$conn->connect_error);
}
else{
	echo"连接成功";
}
?>

 

 

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
 <form name="LoginForm" method="post" action="logincheck.php">
  用户名:
 <p><input type="text" id="ures" name="ures" ></input></p>
 密码:
 <p> <input type="text" id="password" name="password" ></input></p>
   <input type="submit" name="submit" value="确 定  " class="left" />
  </form>
</body>
</html>

 

<?php
header("Content-Type: text/html;charset=utf-8");
$uers=$_POST['ures'];
$password=$_POST['password'];
$con=mysqli_connect("localhost","root","","d1");
if(!$con){
	echo "22";
}
mysqli_select_db($con,"d1");
$re=mysqli_query($con,"SELECT * FROM `test` WHERE username='$uers' and password='$password'");
$a=mysqli_num_rows($re);
echo $a;
if ($a>0){
	 echo"登录成功!";
}
else {
	echo "用户不存在!";
}
mysqli_close($con);
?>

 

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
 <form name="LoginForm" method="post" action="regcheck.php">
  用户名:
 <p><input type="text" id="ures" name="ures" ></input></p>
 密码:
 <p> <input type="text" id="password" name="password" ></input></p>
  确认密码:
  <p><input type="text" id="qrpassword" name="qrpassword" ></input></p>
  <input type="submit" name="submit" value="确 定  " class="left" />
  </form>
</body>
</html>

 

<?php
   header("Content-Type: text/html;charset=utf-8");
   $name=$_POST['ures'];
   $password=$_POST['password'];
   $con=mysqli_connect("localhost","root","","d1");
   if(!$con){
   	echo "22";
   }else{
   }
    mysqli_select_db($con,"d1");
    $result=mysqli_query($con,"SELECT * FROM `test` WHERE  username='$name'");
    $a=mysqli_num_rows($result);
   if ($a>0){
   	 echo "已经存在";
   }
     else {
     	$yu = mysqli_query($con,"INSERT INTO test (username,password) VALUES('$name','$password')");
     	if($yu>0){
     		echo "注册成功!";
     	}else {
     		echo "注册失败!";
     	}
     }
     mysqli_close($con);
?>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值