【问题标题】:Mysqli stmt bind and execute failingMysqli stmt 绑定并执行失败
【发布时间】:2023-03-24 19:12:01
【问题描述】:

我使用 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();
}

非常感谢任何帮助或建议

【问题讨论】:

  • 小记 session_start() 真的应该在脚本的顶部完成
  • 如果你得到它们,你并没有向自己显示任何有用的错误,所以将ini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); 添加到脚本的顶部。这将强制任何 mysqli_ 错误生成您可以在浏览器上看到的异常以及正常的 PHP 错误。
  • 好的,我将这些语句添加到脚本顶部并得到:致命错误:未捕获错误:调用 /home/includes/login.inc.php:26 中未定义的函数 mysqli_stmt_get_result() trace: #0 {main} 在第 26 行的 /home//includes/login.inc.php 中抛出。我不知道如何解决这个问题。第一次看到这个错误。

标签: php mysqli login


【解决方案1】:

进一步测试后发现,在我的 cpanel 中,我没有启用 nd_mysqli。启用它可以解决问题。感谢 RiggsFolly 的帮助

【讨论】:

    猜你喜欢
    • 2014-03-06
    • 1970-01-01
    • 1970-01-01
    • 2014-06-26
    • 1970-01-01
    • 2015-12-07
    • 2017-08-28
    • 2019-07-13
    • 2019-02-24
    相关资源
    最近更新 更多