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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:22:54+00:00 2026-06-01T10:22:54+00:00

Following is my php login script, There are one problem. If i put any

  • 0

Following is my php login script, There are one problem. If i put any password then it’s doesn’t validate the password and it’s going to user panel page. where is the wrong in my code, can anyone tell me the right direction

N:B: I’M NEW IN PHP ALSO NEW IN THIS SITE.

<?php
if(isset($_POST['action']) && isset($_POST['action']) == 'Log In')
{
$uname = mysql_real_escape_string(trim(htmlspecialchars($_POST['uname']))); 
$pass = mysql_real_escape_string(trim(htmlspecialchars($_POST['pass'])));   

$crytpass = hash('sha512','$pass'); 
$err = array();

include_once("toplevel/content/manage/dbcon/dbcon.php");

// check username 
$check_uname = mysql_query("SELECT uname FROM members WHERE uname = '$uname'");
$num_uname = mysql_num_rows($check_uname);

// check password
$check_pass = mysql_query("SELECT pass FROM members WHERE pass = '$crytpass'");
$num_pass = mysql_num_rows($check_pass);

/// userid

$userid = mysql_query("SELECT userid FROM members");    
$re = mysql_fetch_array($userid);
$userid = (int) $re['userid'];


if(isset($uname) && isset($pass))
{
    if(empty($uname) && empty($pass))   
        $err[] = "All field required";  
    else
    {
        // username validation process....

        if(empty($uname))
            $err[] = "Username required";
        else
        {
            if($num_uname == 0)         
            $err[] = "Username is not correct";
        }

        // password validaiton process...

        if(empty($pass))
            $err[] = "Password required";               
        else
        {
            if($num_pass == 0)
            $err[] = "Password is not correct";         
        }

    }
}

if(!empty($err))
{
    foreach($err as $er)
    {
        echo "<font color=red>$er<br></font>";
    }   
}
else
{   
     include("user/include/newsession.php");                   
         header("Location:user/index.php");                     

}

}
?> 
  • 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-01T10:22:55+00:00Added an answer on June 1, 2026 at 10:22 am

    So many thing are wrong here

    Replace

    if (isset ( $_POST ['action'] ) && isset ( $_POST ['action'] ) == 'Log In') {
    

    With

    if (isset ( $_POST ['action'] ) &&  $_POST ['action'] == 'Log In') {
    

    Too many things to replace .. hold on while i rewrite the script for you

    Edit 1

    if (isset ( $_POST ['action'] ) && $_POST ['action'] == 'Log In') {
        $uname = prepareStr ( $_POST ['uname'] );
        $pass = prepareStr ( $_POST ['pass'] );
        $shaPass = hash ( 'sha512', $pass );
        $errors = array ();
    
        include_once ("toplevel/content/manage/dbcon/dbcon.php");
    
        if (! isset ( $uname ) || empty ( $uname )) {
            $err [] = "Empty Username not allowed";
        }
    
        if (! isset ( $pass ) || empty ( $pass )) {
            $err [] = "Empty Password not allowed";
        }
    
        if (count ( $err ) == 0) {
            $mysqli = new mysqli ( "localhost", "root", "", "test" ); // Replace with
                                                                      // DB
                                                                      // Information
            $result = "SELECT uname ,pass FROM members WHERE uname = '$uname' AND pass = '$shaPass'";
    
            if ($result->num_rows > 0) {
                $err [] = "Invalid username or Password";
            }
    
            if (count ( $err ) == 0 && $result) {
                $userInfo = $result->fetch_assoc ();
            /**
             * You can do what every you like here
             */
            }
        }
    
        if (count ( $err ) > 0) {
            /**
             * Kill the user
             */
    
            echo "<pre>";
    
            foreach ( $err as $value ) {
                echo $value . "\n";
            }
            die ( "Die! Die! Die!" );
        }
    
    }
    
    function prepareStr($str) {
        $str = htmlspecialchars ( $str );
        $str = trim ( $str );
        $str = mysql_real_escape_string ( $str );
    
        return $str;
    }
    

    Thanks

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

Sidebar

Related Questions

I've got the following login script.. <?php $name = $_POST[name]; $password = $_POST[password]; $query
i have following script in php to login to mysql $db_host=localhost; $db_user=root; $db_pass=123; $dbc=mysql_connect($db_host,$db_user,$db_pass)
I have a problem with the following piece of PHP script: <?php abstract class
So, when I run this login script, I get the following error: PHP Warning:
I am trying to create a user login/creation script in PHP and would like
I am learning PHP PEAR and testing the following code. However when I login,
I'm following this tutorial: http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/ I've managed to utilize the tut to access and
I am working on my first login script. I have been following examples from
I am trying to cobble together a login script in PHP as a learning
I have the following code to get user data form facebook <div id=fb-root></div> <script>

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.