Help with prepared statement - I am having trouble with the following code, it gets to line 50 then bombs out. The url shows it is still on the page, and displays the echo statement on line 45 (if I uncomment it) but will not go past the $result= line

<?php
if (isset($_POST['login-submit'])) {
  require 'dbh.inc.php';
  $mailuid = $_POST['mailuid'];
  $password = $_POST['pwd'];
  if (empty($mailuid) || empty($password)) {
    header("Location: ../index.php?error=emptyfields&mailuid=".$mailuid);
    exit();
  }
  else {
    $sql = "SELECT * FROM users WHERE uidUsers=? OR emailUsers=?;";
    $stmt = mysqli_stmt_init($conn);
    if (!mysqli_stmt_prepare($stmt, $sql)) {
      header("Location: ../index.php?error=sqlerror");
      exit();
    }
    else {
      mysqli_stmt_bind_param($stmt, "ss", $mailuid, $mailuid); //this is correct allows both logins
      mysqli_stmt_execute($stmt);
      //echo "line 45 gets here";
      //exit();
     
      $result = mysqli_stmt_get_result($stmt);     //what is wrong here?
      echo "line 50 cannot get here";

Did you look at the photos error log to see if there is any error explanation there? There is also the mysqli_error() that might also tell you something.

A) This is the wrong forum section to post questions in.

B) mysqli_stmt_get_result() REQUIRES that the mysqlnd driver be used, which you won’t have control over unless you configure and manage your own web servers, so using it results in non-portable code and should be avoided (you should be getting a fatal php error about that function/method being undefined.)

C) You should switch to the much simpler php PDO extension. In addition to being simpler than the mysqli extension, it doesn’t have any mysqlnd driver dependencies that would result in code working on one server configuration but not another.

Sponsor our Newsletter | Privacy Policy | Terms of Service