duangu3620 2015-10-20 15:03
浏览 19
已采纳

PHP不执行登录表单MySQL

Recently, I was making a login and signup page, where a mail gets sent if you sign up to confirm your account. I used MySQL for the account list, and have a 'confirm' column with 0 (unconfirmed) or 1 (confirmed).

Now, I created the following script to login, but it doesn't seem to be working. After executing this script, I see the "Processing...", then I see the "Such Sadness" part. I have checked in PHPMyAdmin that the account exists, and that it is actually confirmed. MySQL_Base is the file with the connection to the database, and that file is included in other files where the script works.

What is exactly the problem here?

ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
$email = $_POST['email'];
$password = $_POST['password'];
include("mysql_base.php");
echo "Processing...<br>";
$sql = "SELECT * FROM pages_accounts WHERE confirm='1' AND email='".$email."' AND pass='".$password."' LIMIT 1";
if($result = mysqli_query($conn, $sql) &&  $result->num_rows > 0){
  echo "FOUND UR ACCOUNT. MUCH HAPPINESS. SUCH GLAD. WOW REDIRECTING...";
} else {
  echo "SUCH SADNESS. NO ACCOUNT WITH SUCH NAME. WEIRD RETURN. WOW. WHY NOT <a href='loginSignup.php'>SIGNUP</a>?";
}
  • 写回答

1条回答 默认 最新

  • doolo00026 2015-10-20 15:05
    关注

    Replace these 3 lines:

    $query = mysqli_query($conn, $sql);
    $row = mysqli_fetch_assoc($query);
    if(mysql_fetch_array($query) !== false){
    

    with this one:

    if($result = mysqli_query($conn, $sql) &&  $result->num_rows > 0){
    

    UPDATE Last version after discussion in chat:

    if($result = mysqli_query($conn, $sql)) { 
       if ($result->num_rows > 0){ 
          echo "FOUND UR ACCOUNT. MUCH HAPPINESS. SUCH GLAD. WOW REDIRECTING..."; 
       } else { 
          echo "SUCH SADNESS. NO ACCOUNT WITH SUCH NAME. WEIRD RETURN. WOW. WHY NOT <a href='loginSignup.php'>SIGNUP</a>?"; 
       } 
    } else { 
       echo "Errormessage: %s
    ". mysqli_connect_error(); 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 使用Java milo连接Kepserver服务端报错?
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了
  • ¥15 微信小程序商城如何实现多商户收款 平台分润抽成