budder Posted April 20, 2010 Share Posted April 20, 2010 Hey phpfreaks. I wonder if this script would log any of you in, because I'm not getting anywhere when trying. The only thing that happens when i run the script and typing the login information in, is that it refreshes. There is no error in $error and that I don't understand because it should login or display the error message. But maybe it's just me (: <?php session_start(); $dbHost = "s"; $dbUser = "u"; $dbPass = "u"; $dbDatabase = "t"; $db = mysql_connect($dbHost,$dbUser,$dbPass) or die("Unable to connect."); mysql_select_db($dbDatabase, $db) or die(mysql_error($db)); if (isset($_POST['username'])) { $username = trim($_POST['username']); } else { $username = ""; } if (isset($_POST['password'])) { $password = $_POST['password']; } else { $password = ""; } if (isset($_REQUEST['redirect'])) { $redirect = $_REQUEST['redirect']; } else { $redirect = "main.php"; } if (isset($_POST['submit'])) { $query = "SELECT USERNAME FROM site_user WHERE username='" . mysql_real_escape_string($username, $db) . "' AND password = password('" . mysql_real_escape_string($password, $db) . "') $result = mysql_query($query, $db) if (mysql_num_rows($result) > 0) { $_SESSION['username'] = $username; //Line 33 that makes the error. $_SESSION['logged'] = 1; header("Refresh: 5; URL=" . $redirect); echo "<p>Du vil blive sendt videre om 5 sekunder.</p>"; echo "<p>Hvis du ikke bliver sendt videre så klik <a href='" . $redirect . "'>her</a></p>"; die(); } else { $error = "<p>Du har angivet et forkert brugernavn eller kodeord. Prøv igen.</p>"; } } ?> <html> <head> <title>Login</title> </head> <body> <?php if (isset($error)) { echo $error; } ?> <form action="login.php" method"post"> <table> <tr> <td>Username:</td> <td><input type="text" name="username" maxlength="20" size="20" value="<?php echo $username; ?>" /> </td> </tr><tr> <td>Password:</td> <td><input type="password" maxlength="20" size="20" value="<?php $password; ?>" /></td> </tr><tr> <td> </td> <td> <input type="hidden" name="redirect" value="<?php echo $redirect ?>" /> <input type="submit" name="submit" value="login" /> </tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/199122-any-reason-for-not-logging-in/ Share on other sites More sharing options...
ignace Posted April 20, 2010 Share Posted April 20, 2010 You are missing a "; and a ; Try: $query = "SELECT USERNAME FROM site_user WHERE username='" . mysql_real_escape_string($username, $db) . "' AND password = password('" . mysql_real_escape_string($password, $db) . "')"; $result = mysql_query($query, $db); Quote Link to comment https://forums.phpfreaks.com/topic/199122-any-reason-for-not-logging-in/#findComment-1045121 Share on other sites More sharing options...
PFMaBiSmAd Posted April 20, 2010 Share Posted April 20, 2010 Umm. Those are the same two errors that were present in your last thread - http://www.phpfreaks.com/forums/index.php/topic,295093.0.html Any reason for reposting the same code in a new thread after the syntax errors in it were already fixed? Quote Link to comment https://forums.phpfreaks.com/topic/199122-any-reason-for-not-logging-in/#findComment-1045135 Share on other sites More sharing options...
budder Posted April 21, 2010 Author Share Posted April 21, 2010 Hey sorry for putting the same code in that is a mistake. I have edited the error that was present in the script. There are no errors in my script (there is but they are not showed when running the script) but it is not working as I have in mind. As I said in the start it would not login but the $error do not activate as it should if the pass or user is wrong. It's only showing blank page with this in the url: login.php?username=mahe04&redirect=&submit=login Here is the code: <?php session_start(); $dbHost = "sql01.dk"; $dbUser = "elmerdahldk"; $dbPass = "rNnj5Tc2"; $dbDatabase = "elmerdahldk"; $db = mysql_connect($dbHost,$dbUser,$dbPass) or die("Unable to connect."); mysql_select_db($dbDatabase, $db) or die(mysql_error($db)); if (isset($_POST['username'])) { $username = trim($_POST['username']); } else { $username = ""; } if (isset($_POST['password'])) { $password = $_POST['password']; } else { $password = ""; } if (isset($_REQUEST['redirect'])) { $redirect = $_REQUEST['redirect']; } else { $redirect = "main.php"; } if (isset($_POST['submit'])) { $query = "SELECT username FROM site_user WHERE username='" . mysql_real_escape_string($username) . "' AND password = password('" . mysql_real_escape_string($password) . "')"; $result = mysql_query($query, $db); if (mysql_num_rows($result) > 0) { $_SESSION["username"] = $username; $_SESSION['logged'] = 1; header("Refresh: 5; URL=" . $redirect); echo "<p>Du vil blive sendt videre om 5 sekunder.</p>"; echo "<p>Hvis du ikke bliver sendt videre så klik <a href='" . $redirect . "'>her</a></p>"; die(); } else { $error = "<p>Du har angivet et forkert brugernavn eller kodeord. Prøv igen.</p>"; } } ?> <html> <head> <title>Login</title> </head> <body> <?php if (isset($error)) { echo $error; } ?> <form action="login.php" method"post"> <table> <tr> <td>Username:</td> <td><input type="text" name="username" maxlength="20" size="20" value="<?php echo $username; ?>" /> </td> </tr><tr> <td>Password:</td> <td><input type="password" maxlength="20" size="20" value="<?php $password; ?>" /></td> </tr><tr> <td> </td> <td> <input type="hidden" name="redirect" value="<?php echo $redirect ?>" /> <input type="submit" name="submit" value="login" /> </tr> </table> </form> </body> </html> Yes it look like the same code, the difference is that there is no error even when there should be. If the username and password is invaild it should show the $error message. Quote Link to comment https://forums.phpfreaks.com/topic/199122-any-reason-for-not-logging-in/#findComment-1045680 Share on other sites More sharing options...
conker87 Posted April 21, 2010 Share Posted April 21, 2010 You're missing an equals sign. Damnit, the copying screwed up, here it is: <form action="login.php" method="post"> <!-- HERE YOU MISSED AN EQUALS DEFAULTING TO GET --> <table> <tr> <td>Username:</td> <td><input type="text" name="username" maxlength="20" size="20" value="<?php echo $username; ?>" /> </td> </tr><tr> <td>Password:</td> <td><input type="password" maxlength="20" size="20" value="<?php $password; ?>" /></td> </tr><tr> <td> </td> <td> <input type="hidden" name="redirect" value="<?php echo $redirect ?>" /> <input type="submit" name="submit" value="login" /> </tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/199122-any-reason-for-not-logging-in/#findComment-1045713 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.