php 和 mysql(登录表单)

标签 php mysql

 mysql_connect('localhost','root','' ) or die(mysql_error());

mysql_select_db('user_data') or die(mysql_error());

 //This code runs if the form has been submitted
 if (isset($_POST['submit']))
   {
       //This makes sure they did not leave any fields blank
       if (!$_POST['username'] || !$_post['pass'] || !$_POST['pass2'])

       {
           die("fill all the fields");
       }

       // checks if the username is in use
       if(!get_magic_quotes_gpc())
       {
        $_POST['username']= addslashes($_POST['username']);   
       }
       $usercheck = $_POST['username'];

       $check = mysql_query("SELECT username FROM users WHERE username= '$usercheck'") or die(mysql_error());   

       $check2 = mysql_num_rows($check);

        //if the name exists it gives an error
        if($check2 != 0)
        {
        die('sorry, username '.$_POST['username'].' is already in use');    
        }

        //this makes sure both passwords entered match
        if($_POST['pass'] != $_POST['pass2'])
        {
        die('sorry, passwords did not match.'); 
        }

        // here we encrypt the password and add slashes if needed
        $_POST['pass'] = md5($_POST['pass']);
        if(!get_magic_quotes_gpc())
        {
        $_POST['pass']=addslashes($_POST['pass']);
        $_POST['username']=addslashes($_POST['username']);  
        }

        // now we insert it into the database
        $insert= "INSERT INTO users (username,password) VALUES ('".$_POST['username']."','".$_POST['password']."')";
        $add_member = mysql_query($insert);
?>
 <h1>Registered</h1>

 <p>Thank you, you have registered - you may now login</a>.</p>

 <?php 
  } 
 else 
 {  
 ?>
 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<table border="0">

<tr><td>Username:</td><td>

 </td></tr>

 <tr><td>Password:</td><td>

       <input type="password" name="pass" maxlength="10">

  </td></tr>

   <tr><td>Confirm Password:</td><td>

  <input type="password" name="pass2" maxlength="10">

  </td></tr>

 <tr><th colspan=2><input type="submit" name="submit" 
 value="Register"></th></tr> </table>

  </form>


<?php

}
  ?> 

这是我用于登录的脚本,但是当我输入名称、密码并确认密码时,它仍然给我“填写所有字段”的消息,因为我已经填写了所有字段。 任何人都可以帮助我,提前致谢

最佳答案

首先尝试将 !$_post['pass'] 替换为 !$_POST['pass']

希望这有帮助。

关于php 和 mysql(登录表单),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7141443/

相关文章:

php - 通过将 MySQL 与 PHP 分开来保护 MySQL

php - Laravel Orderby 计算值

PHP:glob() 与列出特定文件相比慢了多少?

java - PHP 和 Java 编码问题

PHP - 使用 Ajax 刷新 While 循环数据

php - Laravel:php -S localhost vs php artisan serve

mysql - 合并两个表并将结果相加

python - 无法插入mysql数据库

mysql - Visual Studio 和 MySQL 之间的连接问题

php - 我在哪里可以找到 Yii 应用程序事件列表?