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

  • Home
  • SEARCH
  • 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 909633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:54:46+00:00 2026-05-15T16:54:46+00:00

I am working on my first login script. I have been following examples from

  • 0

I am working on my first login script. I have been following examples from a book, but this is where I am stuck. I want the user login to be an e-mail address, but when I would hit submit, I would get this error.

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\mysite\index.php on line 19

The script works from the book, there’s no typos, and from Google, I found that error is given if the original query fails, so I decided to insert a “mysqli_error” to check what is wrong and I got this:

Nah. admin@mysite.comYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@mysite.com AND password = SHA('password')' at line 1

So, I am almost positive that the @ sign is ending my query early. I have trim and mysql_real_escape_string as a way to clean up the strings, but besides that I have nothing. I have been Googling for a while now and I can’t find or figure out how to make an exception for the @ (“at sign”) or some kind of work around.

I didn’t want this question to be too long or complicated, but I can provide more code if needed.

Thanks!

Edit: Here is the complete code to narrow down the solution.

if (isset($_POST['submit'])) {

    $loginEmail = mysqli_real_escape_string($dbc, trim($_POST['loginEmail']));
    $loginPassword = mysqli_real_escape_string($dbc, trim($_POST['loginPassword']));        

    $query = "SELECT user_id, username FROM user_db WHERE email = $loginEmail AND password = SHA('$loginPassword')";
    $loginData = mysqli_query($dbc, $query);

    if (mysqli_num_rows($loginData) == 1) {
        echo 'You win!';
    }

    else {
        $error = mysqli_error($dbc);
        echo 'Nah. ' . $loginEmail . $error;
    }
}
  • 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-05-15T16:54:46+00:00Added an answer on May 15, 2026 at 4:54 pm

    String literals need to be in single-quotes:

    ...WHERE email = 'accountname@example.com' AND password = SHA('password')
    

    The mysql_real_escape_string() function adds backslashes to special characters within your variable’s content, but it does not delimite the string with single-quotes.

    For example:

    $loginEmail = "O'Reilly";
    $loginEmail = mysql_real_escape_string($loginEmail);
    

    Now the content of $loginEmail is:

    O\'Reilly
    

    Not:

    'O\'Reilly'
    

    So you need to add the quotes in your SQL expression yourself:

    $query = "SELECT user_id, username FROM user_db 
              WHERE email = '$loginEmail' AND password = SHA('$loginPassword')";
    

    I really recommend using PDO and prepared queries instead of all the meticulous interpolation of variables into SQL. That way, you don’t have to worry about mysql_real_escape_string() or quotes or special characters.

    $pdo = new PDO(...connection arguments...);
    $sql = "SELECT * FROM mytable WHERE email = ? AND password = SHA(?)";
    $stmt = $pdo->prepare($sql);
    $stmt->execute(array($loginEmail, $loginPassword));
    

    See? You don’t need to use single-quotes around the ? parameter placeholders, you don’t need to escape the variables you pass as parameters, and yet you don’t need to worry about SQL Injection.

    Also see my presentation SQL Injection Myths and Fallacies.

    Also please read You’re Probably Storing Passwords Incorrectly by fearless leader.

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

Sidebar

Related Questions

Ok, I have this script working 99% of how it should be working, but
I have this code. The code below is working in Firefox, but it is
I'm working with the Head First PHP/MySql book, and have a weird problem with
I am working on a tab based application. The first tab contains the login
I am new to wpf and i am working on first application i have
I'm working on my first game and I have a little over 20 classes.
For a couple of weeks now, I have been working on migrating my client
I've been working on a dynamic question-and-answers system, but I'm having trouble creating a
i am using the following password code http://www.zubrag.com/scripts/password-protect.php it is working fine but when
Trying to get a login script working, I kept getting the same login page

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.