gpt4 book ai didi

php - 卡在我自己的PHP用户注册码中

转载 作者:行者123 更新时间:2023-11-29 04:22:28 27 4
gpt4 key购买 nike

我是一个新的PHP开发人员…我正在创建一个简单的登录表单,用户可以输入他的用户名和密码。。。
当他提交表单,然后用户名将被检查数据库…如果该用户名存在,然后用户将被重定向到一个MSG,用户名已经存在,否则用户名将被添加到数据库……我成功了一半的部分,但不能得到工作另一半…这是我的代码
形式

<form method="post" name="loginvalidate" action="loginvalidate.php">
<p>Username: </p>
<input type="text" name="username" />
<p>Password: </p>
<input type="password" name="password" />
<input type="submit" value="Login" />
</form>

loginvalidate.php登录验证
     <?php include("includes/connect.php"); ?>
<?php


$username = $_POST['username'];
$password = $_POST['password'];

if($username == '' || $password == '')
{

header("Location: index.php?status=error");

}
else
{

$usersql = "SELECT * FROM login where username = '$username'";
$userquery = mysql_query($usersql);


while($row = mysql_fetch_array($userquery))
{



/*THE PROBLEM IS HERE..IN THIS if conidition*/
if($row['username'] != $username)
{

mysql_query("INSERT INTO login (username,password) VALUES ('$username','$password')");
header("Location: index.php?status=OK");


}//end if
else
{


header("Location: index.php?status=userexist");


}//end else



}//ends while

}//end else








?>

如果我输入一个已经在数据库中的用户名,它会工作得很好,并告诉我用户名已经存在于数据库中……但是如果它不存在,它必须将用户名添加到数据库中,但是它什么也不做,什么也没有,没有错误,没有用户添加,没有重定向等。
请告诉我哪里做错了?

最佳答案

替换

   while($row = mysql_fetch_array($userquery))
{
/*THE PROBLEM IS HERE..IN THIS if conidition*/
if($row['username'] != $username)
{

具有
  if(mysql_num_rows($userquery)==0) 
{

并移除
  }//ends while

关于php - 卡在我自己的PHP用户注册码中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19927733/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com