Jump to content

On the login_form page?

 

no no i was saying that for instance if the user entered a wrong username and password it would not let them proceed but to come up with another message saying your username and password was incorrect, do you understand what I'm trying to say?

I am good at computer

Spoiler

Motherboard: Gigabyte G1 sniper 3 | CPU: Intel 3770k @5.1Ghz | RAM: 32Gb G.Skill Ripjaws X @1600Mhz | Graphics card: EVGA 980 Ti SC | HDD: Seagate barracuda 3298534883327.74B + Samsung OEM 5400rpm drive + Seatgate barracude 2TB | PSU: Cougar CMX 1200w | CPU cooler: Custom loop

Link to post
Share on other sites

haha yea i guess

 

You need to alter your PHP script so that instead of "or die()" you redirect back to login_form with a query string. Then use php on the login_form to grab the query string and display an error to the user 

I am good at computer

Spoiler

Motherboard: Gigabyte G1 sniper 3 | CPU: Intel 3770k @5.1Ghz | RAM: 32Gb G.Skill Ripjaws X @1600Mhz | Graphics card: EVGA 980 Ti SC | HDD: Seagate barracuda 3298534883327.74B + Samsung OEM 5400rpm drive + Seatgate barracude 2TB | PSU: Cougar CMX 1200w | CPU cooler: Custom loop

Link to post
Share on other sites

You need to alter your PHP script so that instead of "or die()" you redirect back to login_form with a query string. Then use php on the login_form to grab the query string and display an error to the user 

how exactly do i grab the query strong so that i can display the error?

Link to post
Share on other sites

how exactly do i grab the query strong so that i can display the error?

<?php    if(isset($_GET['error'])){         $error = htmlspecialchars($_GET['error']);    }?>Then down in the error box underneath the form or where you want the error to be displayed, just write<?php echo $error;?>

I am good at computer

Spoiler

Motherboard: Gigabyte G1 sniper 3 | CPU: Intel 3770k @5.1Ghz | RAM: 32Gb G.Skill Ripjaws X @1600Mhz | Graphics card: EVGA 980 Ti SC | HDD: Seagate barracuda 3298534883327.74B + Samsung OEM 5400rpm drive + Seatgate barracude 2TB | PSU: Cougar CMX 1200w | CPU cooler: Custom loop

Link to post
Share on other sites

<?php    if(isset($_GET['error'])){         $error = htmlspecialchars($_GET['error']);    }?>Then down in the error box underneath the form or where you want the error to be displayed, just write<?php echo $error;?>

do i add this is the php script or the form?

Link to post
Share on other sites

Haven't done PHP in years but I'll try to help.

This is part where you check if the username/password combination is stored on the db (from your original code):

<?php$login_query = mysql_query("SELECT * FROM `user` WHERE `username` = '".$_POST['username']."' AND `password` = '".$_POST['password']."'");    // If number of rows is == to 0 (zero) then return error.    if(mysql_num_rows($admin) == 0) {        // Pick error, as this.        die("Wrong username or password.");        // If there is user:    } else {        // Use same query to fetch in array all abou that user, so you can put his ID in session.        $user = mysql_fetch_array($login_query, MYSQL_ASSOC);            $_SESSION['user_id'] = $user['id'];    }} ?>
In the line

if(mysql_num_rows($admin) == 0) {
the variable $admin is uninitialized, I not sure what exactly mysql_num_rows returns when null is given as an argument but I'm pretty sure that's not what you wanted. Depending on what mysql_num_rows returns this either will always be true or always be false.

You probably wanted it to go something like

if(mysql_num_rows($login_query) == 0) {
where you check how many results your login query has.

A few more things:

1. Your sql query also looks vulnerable to sql injection so you should probably sanitize your inputs not just client side but also server side.

2. Don't store passwords in plaintext

3. Your php123 page and pages that require login should do a check whether the user is logged and redirect them to another page if they aren't

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×