MasterACE14 Posted September 30, 2007 Share Posted September 30, 2007 Morning Everyone, I have a homepage called home.php with a username, email and password input box, that form is then submitted to login.php which checks whether anything was entered into the username box, and their is another validation which checks whether the id of the entered username exists, and if it doesnt it displays an error. both validations are working fine. But when I enter a correct account, it goes to login.php and shows a blank page, instead of automatically redirecting to base.php . Could someone please help, I need this fixed urgently! here's login.php: <?php // Login the Player // Process the POST variables $username = $_POST["username"]; if (empty($username)) { // Tell them to enter a correct username, password and e-mail echo "<center><br><br><b>You need to enter a Correct Username, Password and E-mail</b><br><br> <input type=button value=\"Back\" onClick=\"history.go(-1)\"></center>"; die(); }; // Setup the session variables $_SESSION['username'] = $username; // Connect to database ready to match the usernames, then switch over to match the ID $rs = mysql_connect( "localhost", "ace_ACE", "*****" ); $rs = mysql_select_db( "ace_cf" ); // SQL query for all entries in descending order $sql = "SELECT `id` FROM `cf_users` WHERE `username`='" . $username . "' LIMIT 1"; $rs = mysql_query( $sql ) or die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error()); // This gets the data from the result resource //$query = mysql_result($rs,0,0); while($row = mysql_fetch_assoc($rs)){ if(isset($row['id'])){return $row['id'];} } // Put the players ID into a variable $player_id = $query; if (empty($player_id)) { // Tell them to enter a correct username, password and e-mail echo "<center><br><br><b>Their is no Account matching the Username, Password and E-mail address you entered</b><br><br> <input type=button value=\"Back\" onClick=\"history.go(-1)\"></center>"; die(); }; // Put the players ID variable into a session variable $_SESSION['playerid'] = $player_id; if (!empty($player_id)) { // Start the output buffer so we dont create any errors with headers ob_start(); // Automatically redirect the player to the base page header("Location: index.php?page=base"); // End ob ob_end_flush(); }; ?> Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/71300-solved-loginphp-form-validation-error/ Share on other sites More sharing options...
MasterACE14 Posted October 1, 2007 Author Share Posted October 1, 2007 anyone got any idea why it isnt working? Quote Link to comment https://forums.phpfreaks.com/topic/71300-solved-loginphp-form-validation-error/#findComment-358742 Share on other sites More sharing options...
teng84 Posted October 1, 2007 Share Posted October 1, 2007 first remove all your die then see what happens Quote Link to comment https://forums.phpfreaks.com/topic/71300-solved-loginphp-form-validation-error/#findComment-358744 Share on other sites More sharing options...
dingus Posted October 1, 2007 Share Posted October 1, 2007 hey just wanna diagnose the problem so i just poped an echo in the code below if the echo dose work the header throws a wobbly if the echo dose not work we know the ass has fallen out of the IF statement above it so test it and let me know <?php // Login the Player // Process the POST variables $username = $_POST["username"]; if (empty($username)) { // Tell them to enter a correct username, password and e-mail echo "<center><br><br><b>You need to enter a Correct Username, Password and E-mail</b><br><br> <input type=button value=\"Back\" onClick=\"history.go(-1)\"></center>"; die(); }; // Setup the session variables $_SESSION['username'] = $username; // Connect to database ready to match the usernames, then switch over to match the ID $rs = mysql_connect( "localhost", "ace_ACE", "*****" ); $rs = mysql_select_db( "ace_cf" ); // SQL query for all entries in descending order $sql = "SELECT `id` FROM `cf_users` WHERE `username`='" . $username . "' LIMIT 1"; $rs = mysql_query( $sql ) or die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error()); // This gets the data from the result resource //$query = mysql_result($rs,0,0); while($row = mysql_fetch_assoc($rs)){ if(isset($row['id'])){return $row['id'];} } // Put the players ID into a variable $player_id = $query; if (empty($player_id)) { // Tell them to enter a correct username, password and e-mail echo "<center><br><br><b>Their is no Account matching the Username, Password and E-mail address you entered</b><br><br> <input type=button value=\"Back\" onClick=\"history.go(-1)\"></center>"; die(); }; // Put the players ID variable into a session variable $_SESSION['playerid'] = $player_id; if (!empty($player_id)) { echo "look at me i'm inside an if statement"; // Start the output buffer so we dont create any errors with headers ob_start(); // Automatically redirect the player to the base page header("Location: index.php?page=base"); // End ob ob_end_flush(); }; ?> Quote Link to comment https://forums.phpfreaks.com/topic/71300-solved-loginphp-form-validation-error/#findComment-358748 Share on other sites More sharing options...
MasterACE14 Posted October 1, 2007 Author Share Posted October 1, 2007 still stays at login.php and shows a blank page Quote Link to comment https://forums.phpfreaks.com/topic/71300-solved-loginphp-form-validation-error/#findComment-358752 Share on other sites More sharing options...
teng84 Posted October 1, 2007 Share Posted October 1, 2007 where do you set the value for this $player_id = $query;<-- $query??? Quote Link to comment https://forums.phpfreaks.com/topic/71300-solved-loginphp-form-validation-error/#findComment-358758 Share on other sites More sharing options...
trq Posted October 1, 2007 Share Posted October 1, 2007 You logic is a pretty well all over the place. Try... <?php session_start(); $username = $_POST["username"]; if (empty($username)) { echo "<center><br><br><b>You need to enter a Correct Username, Password and E-mail</b><br><br> <input type=button value=\"Back\" onClick=\"history.go(-1)\"></center>"; die(); } mysql_connect( "localhost", "ace_ACE", "*****" ); mysql_select_db( "ace_cf" ); $sql = "SELECT `id` FROM `cf_users` WHERE `username`='" . $username . "' LIMIT 1"; if ($rs = mysql_query( $sql )) { if (mysql_num_rows($rs)) { $row = mysql_fetch_assoc($rs); $_SESSION['username'] = $username; $_SESSION['playerid'] = $row['id']; header("Location: index.php?page=base"); } else { echo "<center><br><br><b>Their is no Account matching the Username, Password and E-mail address you entered</b><br><br> <input type=button value=\"Back\" onClick=\"history.go(-1)\"></center>"; die(); } } else { die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71300-solved-loginphp-form-validation-error/#findComment-358762 Share on other sites More sharing options...
MasterACE14 Posted October 1, 2007 Author Share Posted October 1, 2007 Thats done it! its working perfectly now, Thanks heaps guys Quote Link to comment https://forums.phpfreaks.com/topic/71300-solved-loginphp-form-validation-error/#findComment-358763 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.