Cell0518 Posted June 4, 2006 Share Posted June 4, 2006 I'm piecing together a login utility that checks a MySQL database, and if you are found, it will set 2 session vars (a 3rd for user type, aka admin / regular, etc is commented). At this point, it keeps exiting the loop, not setting a session and never redirecting. The User not validated message keeps showing. I can't seem to figure out what I'm doing wrong. I've used a similar function before, but I can't figure what's wrong. Please help. [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /] Thanks,Chris[code]<!--HEADER GOES HERE--><?phpsession_start();if( $action=="login" && isset($_POST['username'])) { $username = $_POST['username']; $password = $_POST['password']; // MySQL Connection require "config.php"; $conn = mysql_connect("$dblocation","$dbusername","$dbpassword"); if (!$conn) die ("Could not connect MySQL"); { mysql_select_db($dbname,$conn) or die ("Could not open database"); $query = "SELECT user_name, user_group FROM `db1` WHERE user_name = '$username' AND user_password = PASSWORD('$password')"; $result = mysql_query($query); if (mysql_num_rows($result) == 1) { // the user name and password match, $_SESSION['user'] = $username; $_SESSION['loggedIn'] = true; /*while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $userGroup = $row['user_group']; echo $userGroup; session_register("userGroup"); //is this really needed? $_SESSION['userGroup'] = $userGroup; }*/ header("Location: ".$url); } } // nothing became valid while we looped so verification failed echo "<b>Incorrect Username or Password</b><p />";}elseif($action=="logout") { session_start(); session_unset(); session_destroy(); echo '<b>You have successfully logged out!</b><p />';}else {}?><form action="admin.php?action=login" method="post"> <p>Username: <input type="text" name="username"><br> <p>Password : <input type="password" name="password"><br> <input type="submit" value=" Login "></form><!-- REST OF FOOTER-->[/code] Link to comment https://forums.phpfreaks.com/topic/11165-login-utility-not-working/ Share on other sites More sharing options...
wildteen88 Posted June 4, 2006 Share Posted June 4, 2006 Change this code:[code]$_SESSION['loggedIn'] = true; /*while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $userGroup = $row['user_group']; echo $userGroup; session_register("userGroup"); //is this really needed? $_SESSION['userGroup'] = $userGroup; }*/ header("Location: ".$url);[/code]to the following:[code]$_SESSION['loggedIn'] = true; $row = mysql_fetch_array($result); $_SESSION['userGroup'] = $row['user_group']; header("Location: ".$url);[/code]Also I see yoou have the following:[code]<!--HEADER GOES HERE--><?php[/code]Is that going to be HTML where <!--HEADER GOES HERE--> currently is? If it is then session_start will fail to work and your header redirect will fail too. As these function require no output before the use of those functtions. Link to comment https://forums.phpfreaks.com/topic/11165-login-utility-not-working/#findComment-41800 Share on other sites More sharing options...
Cell0518 Posted June 4, 2006 Author Share Posted June 4, 2006 Wildteen88,It worked, thanks for you help. :)CL Link to comment https://forums.phpfreaks.com/topic/11165-login-utility-not-working/#findComment-41882 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.