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
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)) {

 

Link to comment
Share on other sites

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.