[英]Unknown issue with PHP registration form
I'm trying to make a PHP login system, and I can't figure out what's causing it to not work. 我正在尝试制作一个PHP登录系统,但我不知道是什么原因导致它无法正常工作。
Below is the PHP code from the register page. 以下是来自注册页面的PHP代码。 When executed, it fails to create a new user account.
执行后,它将无法创建新的用户帐户。
<?php
if(isset($_POST['submit_btn']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$cpassword = $_POST['cpassword'];
if($_password==$_cpassword)
{
$query= "SELECT * FROM user WHERE username='$username'";
$query_run = mysqli_query($con,$query);
if(mysqli_num_rows($query_run)>0)
{
echo '<script type="text/javascript">alert("This Username Already exists.. Please try another username!")</script>';
}
{
$query= "insert into user values('$username','$password')";
$query_run = mysqli_query($con,$query);
if($query_run)
{
echo '<script type="text/javascript">alert("User registered. Please login")</script>';
}
else
{
'<script type="text/javascript">alert("Error!")</script>';
}
}
}
}
?>
The problem is here 问题在这里
if($_password==$_cpassword)
You'd defined these variables: 您已经定义了以下变量:
$password = $_POST['password'];
$cpassword = $_POST['cpassword'];
So, use $password
and $cpassword
instead 因此,请改用
$password
和$cpassword
if($password == $cpassword)
...
By the way, your code is vulnerable to SQL injection attack. 顺便说一句,您的代码容易受到SQL注入攻击。 Use prepared statements .
使用准备好的陈述 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.