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 7852487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:25:46+00:00 2026-06-02T19:25:46+00:00

What am I doing wrong here: <?php if (isset($_POST[‘submitted’])) { $errors = array(); require_once

  • 0

What am I doing wrong here:

<?php
    if (isset($_POST['submitted'])) {

    $errors = array();
        require_once ('mysql_connect.php');

    session_start();
    $username = $_POST["username"]; // This is the inputted username from the form in Login.html
    $password = $_POST["password"]; // This is the inputted password from the form in Login.html


    if (empty($errors)) {
        $query="SELECT username FROM users WHERE username='$username' AND password='SHA($password)'"; 

        $result = mysql_query($query);  

        // Mysql_num_row is counting table row

        if (mysql_num_rows($result) == 1) {
                $_SESSION["username"] = $username; // Creates a cookie saving the username
                $_SESSION["loggedIn"] = true; // Creates a cookie saying the user is logged in
            // Show thank you message
            echo '<h3 style="color:green;">Thank You!</h3>
            <span style="color:green;">You have been logged in.</span>';
        } else {
            echo '<font color="red">You could not be logged in, please make sure your username and password is correct.</font>';
            foreach ($errors as $msg) {
            echo " - <font color=\"red\">$msg</font><br />\n";
            }
        }

} else {
        echo '<font color="red"><h3>Error!</h3>
        The following error(s) occured:<br /></font>';

        foreach ($errors as $msg) {
            echo " - <font color=\"red\">$msg</font><br />\n";
        }
    }
}
?>

I get a:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /login.php on line 19

Also is the way I SHA the password correct?

  • 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-02T19:25:47+00:00Added an answer on June 2, 2026 at 7:25 pm

    The problem is that your MySQL query is causing an error, which means that your $result doesn’t actually contain a result resource.

    You need to remove the '' from around SHA($password) in your query, and instead put them around the password value, like so:

    $query="SELECT username FROM users WHERE username='$username' AND password=SHA('$password')";
    

    Also is the way I SHA the password correct?

    That depends on how the passwords were hashed when they were inserted into the database. MySQL’s SHA() is the same as its SHA-1():

    Calculates an SHA-1 160-bit checksum for the string, as described in RFC 3174

    Which is also the same as PHP’s sha1(); so, for example, if the passwords in the database are SHA-1 hashes that were created using PHP’s sha1(), it should be fine.


    Side Notes

    • You should use PHP’s crypt() or hash() for hashing passwords, rather than SHA-1. For example usage, refer to the PHP documentation.

    • You should be cleaning/escaping all user-provided data before using any of it in a database query. This is to stop SQL injection attacks. Better yet, use prepared statements and parameterized queries. Refer to this answer for more information.

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

Sidebar

Related Questions

Here's what I am doing, <?php if(isset($_POST['submit'])){ $text_area= mysqli_real_escape_string($dbc, strip_tags(trim($_POST['text_area']))); echo $text_area; } ?>
What am I doing wrong here folks? <?php include 'header.php'; /** * Display a
PHP session_start(); $username = $_POST['regduser']; $userpass = md5($_POST['regdpass']); $sql = $sql->prepare(SELECT * from Students
What am I doing wrong here? I'm trying to get started with jQuery UI
What am I doing wrong here: class Helo { // main: generate some simple
What am I doing wrong here? I'm serializing a value, storing it in a
What am I doing wrong here? private void SendMail(string from, string body) { string
What am I doing wrong here? Im trying to save a canvas drawing by
What am I doing wrong here? It says Database Count Failed (on the $count
What am I doing wrong here? Declare @starttimestamp datetime = getdate(); RAISERROR(N'Code not valid

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.