Letterbomb05 Posted May 23, 2008 Share Posted May 23, 2008 Hello, I really need this Login Script completed, and I haven't got it working in the past 5 days, and I'm getting very frustrated!!! My problems are: A) As far as I'm aware, the SESSION doesn't get set B) When I login with the correct details, all that really happens is the page gets refreshed, I don't get take to info.php or anything! PLEASE HELP! Code: <?php // start of login script // database information $dbhost = "localhost"; $dbname = ""; $dbuser = ""; $dbpass = ""; // connect to database mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); // start session session_start(); // retrieve form input $username = htmlentities(mysql_real_escape_string($_POST['username'])); $password = (md5($_POST['password'])); // query the database $query = "SELECT * from users WHERE username='$username' and password='$password'"; $result = mysql_query($query); $aAssoc = mysql_fetch_assoc($result); $rank = $qAssoc['rank']; if(mysql_num_rows($result) === 0 || $aAssoc['rank'] == 0){ include('incorrect.php'); }else{ if($rank = 1){ $SESSION['registered'] = true; } if($rank = 2){ $SESSION['member'] = true; } if($rank = 3){ $SESSION['moderator'] = true; } if($rank = 4){ $SESSION['admin'] = true; } header("Location: info.php"); } // end of script ?> Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/ Share on other sites More sharing options...
DeanWhitehouse Posted May 23, 2008 Share Posted May 23, 2008 session_start(); need that at the begging of the code. on the first line Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548470 Share on other sites More sharing options...
Letterbomb05 Posted May 23, 2008 Author Share Posted May 23, 2008 Is that all thats wrong..? I mean i have session_start() on all other pages Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548475 Share on other sites More sharing options...
DeanWhitehouse Posted May 23, 2008 Share Posted May 23, 2008 should be ,and change the header to a complete address like header("Location:http://".$_SERVER['HTTP_HOST']."/info.php") Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548480 Share on other sites More sharing options...
phpzone Posted May 23, 2008 Share Posted May 23, 2008 $rank = $qAssoc['rank']; This line should be: $rank = $aAssoc['rank'] and all lines like if($rank = 1){ should be : if ( $rank == 1 ) { Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548483 Share on other sites More sharing options...
Letterbomb05 Posted May 23, 2008 Author Share Posted May 23, 2008 lol @ that first one, I'm sorry I'm tired and I always miss small little things like that. I'll edit this post in a sec and see if there is any progress. Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548484 Share on other sites More sharing options...
Letterbomb05 Posted May 23, 2008 Author Share Posted May 23, 2008 still does the same as before: <?php session_start(); // database information $dbhost = ""; $dbname = ""; $dbuser = ""; $dbpass = ""; // connect to database mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); // retrieve form input $username = htmlentities(mysql_real_escape_string($_POST['username'])); $password = (md5($_POST['password'])); // query the database $query = "SELECT * from users WHERE username='$username' and password='$password'"; $result = mysql_query($query); $aAssoc = mysql_fetch_assoc($result); $rank = $qAssoc['rank']; if(mysql_num_rows($result) === 0 || $qAssoc['rank'] == 0){ include('incorrect.php'); }else{ if ( $rank == 1 ) { $SESSION['registered'] = true; } if ( $rank == 2 ) { $SESSION['member'] = true; } if ( $rank == 3 ) { $SESSION['moderator'] = true; } if ( $rank == 4 ) { $SESSION['admin'] = true; } header("Location:http://www.team-recoil.com/newtemplate/info.php"); } // end of script ?> Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548489 Share on other sites More sharing options...
BlueSkyIS Posted May 23, 2008 Share Posted May 23, 2008 for the record: session_start() doesn't necessarily have to be at the beginning of the code. Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548493 Share on other sites More sharing options...
Letterbomb05 Posted May 23, 2008 Author Share Posted May 23, 2008 really need help, PLEASE someone help me sort this out >_> Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548523 Share on other sites More sharing options...
BlueSkyIS Posted May 23, 2008 Share Posted May 23, 2008 update to this and see what you get in query: $result = mysql_query($query) or die(mysql_error()); echo "query: $query"; Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548524 Share on other sites More sharing options...
peranha Posted May 23, 2008 Share Posted May 23, 2008 This line $rank = $qAssoc['rank']; needs to be $rank = $aAssoc['rank']; Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548529 Share on other sites More sharing options...
BlueSkyIS Posted May 23, 2008 Share Posted May 23, 2008 already noted by phpzone, above. Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548530 Share on other sites More sharing options...
Letterbomb05 Posted May 23, 2008 Author Share Posted May 23, 2008 BlueSkyIS, I did what you said but nothing happened. Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548532 Share on other sites More sharing options...
peranha Posted May 23, 2008 Share Posted May 23, 2008 already noted by phpzone, above. yes, but the code posted after does not have it changed in it. So just making sure it is changed. Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548538 Share on other sites More sharing options...
BlueSkyIS Posted May 23, 2008 Share Posted May 23, 2008 thanks, peranha! BlueSkyIS, I did what you said but nothing happened. you don't see query: or anything? ??? can you post the latest code? Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548540 Share on other sites More sharing options...
Letterbomb05 Posted May 23, 2008 Author Share Posted May 23, 2008 1 second just noticed something Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548544 Share on other sites More sharing options...
phpzone Posted May 23, 2008 Share Posted May 23, 2008 It would have died before printing the query because of the die(mysql_error()) No message from mysql_error() ? the echo would need to be before the statement is executed, but there should be an error dumped try adding the following to the top of your script: error_reporting( E_ALL ); set_ini('display_errors','On'); Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548548 Share on other sites More sharing options...
Letterbomb05 Posted May 23, 2008 Author Share Posted May 23, 2008 Nope everything is pretty much in the same state it was earlier latest code: <?php session_start(); // database information $dbhost = ""; $dbname = ""; $dbuser = ""; $dbpass = ""; // connect to database mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); // retrieve form input $username = htmlentities(mysql_real_escape_string($_POST['username'])); $password = (md5($_POST['password'])); // query the database $query = "SELECT * from users WHERE username='$username' and password='$password'"; $result = mysql_query($query) or die(mysql_error()); echo "query: $query"; $qAssoc = mysql_fetch_assoc($result); $rank = $qAssoc['rank']; if(mysql_num_rows($result) === 0 || $qAssoc['rank'] == 0){ include('incorrect.php'); }else{ if ( $rank == 1 ) { $SESSION['registered'] = true; } if ( $rank == 2 ) { $SESSION['member'] = true; } if ( $rank == 3 ) { $SESSION['moderator'] = true; } if ( $rank == 4 ) { $SESSION['admin'] = true; } header("Location:http://www.team-recoil.com/newtemplate/info.php"); } // end of script ?> Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548550 Share on other sites More sharing options...
Letterbomb05 Posted May 23, 2008 Author Share Posted May 23, 2008 It would have died before printing the query because of the die(mysql_error()) No message from mysql_error() ? the echo would need to be before the statement is executed, but there should be an error dumped try adding the following to the top of your script: error_reporting( E_ALL ); set_ini('display_errors','On'); Where should I put that snippet? Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548551 Share on other sites More sharing options...
phpzone Posted May 23, 2008 Share Posted May 23, 2008 You might need a space after "Location: " Perhaps. Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548553 Share on other sites More sharing options...
Letterbomb05 Posted May 23, 2008 Author Share Posted May 23, 2008 PHPzone, where abouts should I put the snippet you gave me? Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548557 Share on other sites More sharing options...
phpzone Posted May 23, 2008 Share Posted May 23, 2008 Where should I put that snippet? "try adding the following to the top of your script:" error_reporting( E_ALL ); set_ini('display_errors','On'); Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548558 Share on other sites More sharing options...
Letterbomb05 Posted May 23, 2008 Author Share Posted May 23, 2008 ugh, sorry, tiredness lol, I'll try that, one second. Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548559 Share on other sites More sharing options...
phpzone Posted May 23, 2008 Share Posted May 23, 2008 Yeah, a good sleep and some Zen meditation usually helps Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548560 Share on other sites More sharing options...
Letterbomb05 Posted May 23, 2008 Author Share Posted May 23, 2008 Still have absolutely nothing. Quote Link to comment https://forums.phpfreaks.com/topic/107002-solved-please-help/#findComment-548561 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.