Jump to content

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

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.