Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to login make a PHP login script work but I receive as an errors:
Warning: mysqli_stmt::bind_result(): Number of bind variables doesn't match number of fields in prepared statement in /hermes/bosnaweb25a/b2739/d5.sfconsul/public_html/daaseed.com/Player/login.php on line 32 Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosnaweb25a/b2739/d5.sfconsul/public_html/daaseed.com/Player/index.php:3) in /hermes/bosnaweb25a/b2739/d5.sfconsul/public_html/daaseed.com/Player/login.php on line 36

index.php
<?php
include('login.php'); // Includes Login Script
if(isset($_SESSION['login_user'])){
header("location: profile.php"); // Redirecting To Profile Page
    exit();
}
?>
login.php
<?php
session_start(); // Starting Session 

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$error = ''; // Variable To Store Error Message 
if (isset($_POST['submit'])) { 
  if (empty($_POST['username']) || empty($_POST['password'])) { 
    $error = "Username or Password is invalid"; 
  } 
  else{ 
    // Define $username and $password 
    $username = $_POST['username']; 
    $password = $_POST['password']; 
    // mysqli_connect() function opens a new connection to the MySQL server. 
   // $conn = mysqli_connect("localhost", "root", "", "customers"); 
      mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

       $conn = mysqli_connect(......); 

    // SQL query to fetch information of registerd users and finds user match. 
    $query = "SELECT username, password, Paid from customers where username=? AND password=? AND Paid='y' LIMIT 1"; 
    // To protect MySQL injection for Security purpose 
    $stmt = $conn->prepare($query); 
    $stmt->bind_param("ss", $username, $password); 
    $stmt->execute(); 
    $stmt->bind_result($username, $password); 
    $stmt->store_result(); 
    if($stmt->fetch()) //fetching the contents of the row { 
      $_SESSION['login_user'] = $username; // Initializing Session 
    header("location: profile.php"); // Redirecting To Profile Page 
  }
  mysqli_close($conn); // Closing Connection 
} 
?>
I receive the errors when trying to login. I tried googling it but with no luck of finding the right solution. How to fix the issues?


What I have tried:

I noticed that this errors occur only when on server. I tried on localhost-no problems. Of course, I changed the mysqli statement but It seems that something else is wrong.
Posted
Updated 29-Jul-19 23:08pm
Comments
Richard Deeming 30-Jul-19 10:31am    
You're storing passwords in plain text. Don't do that.
Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

PHP includes functions to help you do the right thing:
PHP: password_hash[^]
PHP: password_verify[^]

1 solution

PHP
$query = "SELECT username, password, Paid from customers where username=? AND password=? AND Paid='y' LIMIT 1";
// To protect MySQL injection for Security purpose
$stmt = $conn->prepare($query);
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$stmt->bind_result($username, $password);

Your SELECT statement requests three variables, but your bind_result only specifies two.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900