Mysqli stmt绑定并执行失败

问题描述 投票:0回答:1

我使用mysqli创建了一个登录页面。在注释掉if语句以找出错误所在的位置之后,错误看起来就在这段代码中:

mysqli_stmt_bind_param($stmt, "ss", $mailuid, $mailuid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);

尝试运行此脚本时,出现500错误。我找不到任何语法或命名错误。


这是完整的脚本:

<?php
if(isset($_POST['login-submit'])) {
  require('dbh.inc.php');

  $mailuid = $_POST['mailuid'];
  $password = $_POST['pwd'];

  if (empty($mailuid) || empty($password)) {
    header('location: ../admin.php?error=emptyfields');
    exit();
  } else {
    $sql = "SELECT * FROM adminAccounts WHERE uid_user = ? OR email_user = ?;";
    $stmt = mysqli_stmt_init($conn);

    if (!mysqli_stmt_prepare($stmt, $sql)) {
      header('location: ../admin.php?error=sqlerror');
      exit();
    } else {
      mysqli_stmt_bind_param($stmt, "ss", $mailuid, $mailuid);
      mysqli_stmt_execute($stmt);
      $result = mysqli_stmt_get_result($stmt);

      if ($row = mysqli_fetch_assoc($result)) {
        $pwdCheck = password_verify($password, $row['pwd_user']);

        if ($pwdCheck == false) {
          header('location: ../admin.php?error=wrongpassword');
          exit();
        } else if ($pwdCheck == true) {
          session_start();
          $_SESSION['userID'] = $row['id_user'];
          $_SESSION['userUID'] = $row['uid_user'];

          header('location: ../index.php?login=success');
          exit();
        } else {
          header('location: ../admin.php?error=wrongpassword');
          exit();
        }
      } else {
        header('location: ../admin.php?error=nouser');
        exit();
      }
    }
  }
} else {
  header('location: ../index.php');
  exit();
}

任何帮助或建议将非常感谢

php mysqli login
1个回答
0
投票

经过进一步测试后发现,在我的cpanel中我没有启用nd_mysqli。启用它修复了问题。感谢RiggsFolly的帮助

© www.soinside.com 2019 - 2024. All rights reserved.