Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9118861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:15:21+00:00 2026-06-17T05:15:21+00:00

I have been coding a login script in PHP using prepared statements however I

  • 0

I have been coding a login script in PHP using prepared statements however I can’t get it to work, can anyone point out why this isn’t working?

Whenever I log in all I get is the “Statement failed!”.

//Start session
session_start();

//Include database connection details
require_once('config.php');

    //Sanitize the POST values
$login = clean($_POST['login']);
$password = clean($_POST['password']);

$query = $dbconn -> prepare("SELECT * FROM members WHERE login=? AND passwd=?");
$query -> bind_param("ss", $login, $password);

if($query->execute() == true) {
    $query -> bind_result($result);
    $query -> fetch();
    if($result){
            $member = mysqli_fetch_assoc($result);
            session_regenerate_id();
            $_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
            $_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
            $_SESSION['SESS_LAST_NAME'] = $member['lastname'];
            $_SESSION['SESS_IS_ADMIN'] = $member['admin'];
            session_write_close();
            echo $_SESSION['SESS_MEMBER_ID'];
            echo $_SESSION['SESS_FIRST_NAME'];
            echo "Test!";
            exit();
    }else{
            echo "Statement failed";
    }
}
/* Close statement */
$query -> close();

In config.php there is the following:

$dbconn = new mysqli('localhost', 'root', 'password', 'bookingsystem');

And the database structure for the users looks like this:

`members` (`member_id`, `firstname`, `lastname`, `login`, `passwd`, `admin`) VALUES
(1, 'Steve', 'Stone', 'Admin', '5f4dcc3b5aa765d61d8327deb882cf99', 1);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:15:23+00:00Added an answer on June 17, 2026 at 5:15 am

    From the manual on bind_result:

    Note that all columns must be bound after mysqli_stmt_execute() and
    prior to calling mysqli_stmt_fetch().

    You are binding one variable but you are selecting 6 columns. You need to bind all 6 columns to a variable and then inside the condition, you do not have to fetch another row as you have already done that and the results from your fetch will be available in your variables.

    You should also check for the return value of fetch, not $result or any of the other variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ive never heard of this before, and I have been coding in PHP for
I have been looking at either coding from scratch a basic login page +
Greetings, Well I am bewildered. I have been tasked with updating a PHP script
I have been coding regurlarly in C++ in the past months. I am getting
I've been coding a very sizable project and I have run into trouble with
I've been coding in Java for the past year, and i think I have
In our company's coding standard, we have been told to be aware of the
Im very new to all coding including jquery. I though this would have been
I am 2 days old with python and coding in general, I have been
So, I've been coding for a little (2 years), and I have a very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.