Jump to content

[SOLVED] User Login Page Help?


jbingman

Recommended Posts

what i have right now is...

 

<?php

$connect = mysql_connect("localhost","username","password");

$db = mysql_select_db("database");

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

if(mysql_num_rows(mysql_query("SELECT username, password FROM accounts WHERE username = '".$_POST['username']."' && password = '".$_POST['password']."' ")) >0) {

if(mysql_num_rows(mysql_query("SELECT id FROM accounts WHERE username = '".$_POST['username']."' && password = '".$_POST['password']."' ")) > 0 ) {

        $_SESSION['logged'] = true;

        $_SESSION['username'] = $_POST['username'];

        $_SESSION['password'] = $_POST['password'];

        echo "<p style=\"color:green;font-size:12px\">You have successfully logged in!</p>";

  }else{ //if the username and password aren't from the same account but does exist

     echo "<p style=\"color:red;font-size:12px\" align=\"center\"> Incorrect login! Please try again</p>";

  }

}else{ //username/password doesn't exist

  echo "<p style=\"color:red;font-size:12px\" align=\"center\">Username/Password doesn't exist!</p>";

}

}

 

 

?>

 

Where you have [echo "<p style=\"color:green;font-size:12px\">You have successfully logged in!</p>";] replace that with header( 'Location: login.html' ) and that will as soon as they have login in redirect you to what ever page you want.

 

<?php
$connect = mysql_connect("localhost","username","password");
$db = mysql_select_db("database");
if(isset($_POST['login'])) {
if(mysql_num_rows(mysql_query("SELECT username, password FROM accounts WHERE username = '".$_POST['username']."' && password = '".$_POST['password']."' ")) >0) {
if(mysql_num_rows(mysql_query("SELECT id FROM accounts WHERE username = '".$_POST['username']."' && password = '".$_POST['password']."' ")) > 0 ) {
         $_SESSION['logged'] = true;
         $_SESSION['username'] = $_POST['username'];
         $_SESSION['password'] = $_POST['password'];
         echo header( 'Location: login.html' );
   }else{ //if the username and password aren't from the same account but does exist
      echo "<p style=\"color:red;font-size:12px\" align=\"center\"> Incorrect login! Please try again</p>";
   }
}else{ //username/password doesn't exist
   echo "<p style=\"color:red;font-size:12px\" align=\"center\">Username/Password doesn't exist!</p>";
}
}


?>

And then you need to go about creating a page that checks the session to see if they you are logged in which is shown in the tutorials

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.