Jump to content

Nooby Login Script Problem


pianoman993

Recommended Posts

Hey guys, I've got an extremely nooby login script. Among other problems, none of the passwords are encyrpted, which they will be. This is just a simple simple script. Here is the code I wrote, it does not work evidently. Is there any reason why? If so could post the revised code please. Many thanks to everyone.

 

<?php

 

error_reporting(E_ALL | E_STRICT);

ini_set('display_errors', True);

 

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

 

            $username = htmlentities($_POST['login_username']);

            $password = htmlentities($_POST['login_password']);

 

            // Connect to database

            require_once('../excludes/dbc.php');

            $connection = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

            if (!$connection) die('Could not connect to host');

            mysql_select_db(DB_NAME, $connection);

 

            $result = mysql_query("SELECT username, password FROM users WHERE username = '$username' AND password = '$password' ");

 

            if($result) $row = mysql_fetch_array($result, MYSQL_ASSOC);

 

            if(($row['username'] = $username) AND ($row['password'] = $password)) {

            $loggenin = TRUE;

            echo '<b>You have successfully logged in!</b><br />Welcome '.$username;

            echo '<br /><a href="?">Back up</a>';

            } else {

            $loggenin = False;

            echo '<b><span style="color:red">Login failed</span></b>';

            echo '<br /><a href="?">Back up</a>';

            }

 

 

} else {

  echo "<form action='?' method='post' class='login'>

  Username:<br /><input name='login_username' class='text_input width_100' type='text' /><div class='space'></div>

  Password:<br /><input name='login_password' class='text_input width_100' type='password' /><br />

  <div class='space'></div><input type='checkbox' class='checkbox_input'/>Remember me<br /><div class='space'></div>

  <input type='submit' name='login_submit' value='Login' class='click_input' />

  <div class='space'></div><a class='s_10 forgotpassword' href='#'>Forgot Password?</a>

  </form>";

}

 

?>

Link to comment
https://forums.phpfreaks.com/topic/81229-nooby-login-script-problem/
Share on other sites

here is where a problem lies, I dont know if its your actual problem but it wont be helping

if(($row['username'] = $username) AND ($row['password'] = $password)) {

 

a single = sign assigns a value to a variable, if you are checking for equality it should be a == such as

 

if(($row['username'] == $username) AND ($row['password'] == $password)) {

 

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.