pianoman993 Posted December 11, 2007 Share Posted December 11, 2007 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>"; } ?> Quote Link to comment Share on other sites More sharing options...
paul2463 Posted December 11, 2007 Share Posted December 11, 2007 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)) { Quote Link to comment Share on other sites More sharing options...
pianoman993 Posted December 11, 2007 Author Share Posted December 11, 2007 ahhh very wise indeed. Thanks for the post! Quote Link to comment Share on other sites More sharing options...
runnerjp Posted December 11, 2007 Share Posted December 11, 2007 would it not be nicer the redirect users to a different page when logged in? Quote Link to comment Share on other sites More sharing options...
revraz Posted December 11, 2007 Share Posted December 11, 2007 May want to fix this or you won't get far "<form action='?' method='post' class='login'> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.