jusjus7 Posted January 30, 2012 Author Share Posted January 30, 2012 Is the name of the page we're working on called checklogin2.php? yes it goes from loginre1.php to checklogin2.php and from there it should go to login_success.php, login_success2.php or login_success4.php (depending on user year) Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/3/#findComment-1312382 Share on other sites More sharing options...
Drummin Posted January 30, 2012 Share Posted January 30, 2012 Change to this <?php session_start(); //ini_set('session.bug_compat_42',0); //ini_set('session.bug_compat_warn',0); $host="localhost"; // Host name $username="phpuser"; // username $password="phpuser"; // password $db_name="phpsite"; // Database name $tbl_name="users"; // Table name // Replace database connect functions depending on database you are using. mysql_connect("$host", "$username", "$password"); mysql_select_db("$db_name"); //Add isset if (isset($_POST['UsersID'])){ //submitting query // username and password sent from form //NEVER Remove the mysql_real_escape_string. Else there could be an Sql-Injection! $UsersID=mysql_real_escape_string($_POST['UsersID']); $U_Password=mysql_real_escape_string($_POST['U_Password']); $sql="SELECT UsersID,U_YearID FROM users WHERE UsersID='$UsersID' and U_Password='$U_Password'"; //echo $sql; $result = mysql_query($sql); $result2=mysql_fetch_row($result); //checking results // Replace counting function based on database you are using. $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row //Direct Userbased on result if($count==1){ // Register $UsersID, $U_Password and redirect to file "login_success.php" /* $_SESSION['UsersID']=$result[0]; $_SESSION['U_YearID']=$result[1]; if($_SESSION['U_YearID']==1){ header("location:login_success.php"); exit; } if($_SESSION['U_YearID']==2){ header("location:login_success2.php"); exit; } if($_SESSION['U_YearID']==4){ header("location:login_success4.php"); exit; } */ echo "{$result2[1]}"; } else { echo "Wrong Username or Password"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/3/#findComment-1312383 Share on other sites More sharing options...
jusjus7 Posted January 30, 2012 Author Share Posted January 30, 2012 Change to this line $result=mysql_fetch_row($sql); i get this Warning: mysql_fetch_row() expects parameter 1 to be resource, string given in C:\xampp\htdocs\Site1\test\checklogin2.php on line 29 Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Site1\test\checklogin2.php on line 32 Wrong Username or Password Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/3/#findComment-1312385 Share on other sites More sharing options...
Drummin Posted January 30, 2012 Share Posted January 30, 2012 Notice EDIT above. Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/3/#findComment-1312386 Share on other sites More sharing options...
jusjus7 Posted January 30, 2012 Author Share Posted January 30, 2012 Notice EDIT above. i get 1 displayed on the page Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/3/#findComment-1312387 Share on other sites More sharing options...
Drummin Posted January 30, 2012 Share Posted January 30, 2012 Now try this <?php session_start(); //ini_set('session.bug_compat_42',0); //ini_set('session.bug_compat_warn',0); $host="localhost"; // Host name $username="phpuser"; // username $password="phpuser"; // password $db_name="phpsite"; // Database name $tbl_name="users"; // Table name // Replace database connect functions depending on database you are using. mysql_connect("$host", "$username", "$password"); mysql_select_db("$db_name"); //Add isset if (isset($_POST['UsersID'])){ //submitting query // username and password sent from form //NEVER Remove the mysql_real_escape_string. Else there could be an Sql-Injection! $UsersID=mysql_real_escape_string($_POST['UsersID']); $U_Password=mysql_real_escape_string($_POST['U_Password']); $sql="SELECT UsersID,U_YearID FROM users WHERE UsersID='$UsersID' and U_Password='$U_Password'"; $result = mysql_query($sql); $result2=mysql_fetch_row($result); //checking results // Replace counting function based on database you are using. $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row //Direct Userbased on result if($count==1){ // Register $UsersID, $U_Password and redirect to file "login_success.php" $_SESSION['UsersID']=$result2[0]; $_SESSION['U_YearID']=$result2[1]; if($_SESSION['U_YearID']==1){ header("location:login_success.php"); exit; } if($_SESSION['U_YearID']==2){ header("location:login_success2.php"); exit; } if($_SESSION['U_YearID']==4){ header("location:login_success4.php"); exit; } } else { echo "Wrong Username or Password"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/3/#findComment-1312388 Share on other sites More sharing options...
jusjus7 Posted January 30, 2012 Author Share Posted January 30, 2012 Now try this <?php session_start(); //ini_set('session.bug_compat_42',0); //ini_set('session.bug_compat_warn',0); $host="localhost"; // Host name $username="phpuser"; // username $password="phpuser"; // password $db_name="phpsite"; // Database name $tbl_name="users"; // Table name // Replace database connect functions depending on database you are using. mysql_connect("$host", "$username", "$password"); mysql_select_db("$db_name"); //Add isset if (isset($_POST['UsersID'])){ //submitting query // username and password sent from form //NEVER Remove the mysql_real_escape_string. Else there could be an Sql-Injection! $UsersID=mysql_real_escape_string($_POST['UsersID']); $U_Password=mysql_real_escape_string($_POST['U_Password']); $sql="SELECT UsersID,U_YearID FROM users WHERE UsersID='$UsersID' and U_Password='$U_Password'"; $result = mysql_query($sql); $result2=mysql_fetch_row($result); //checking results // Replace counting function based on database you are using. $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row //Direct Userbased on result if($count==1){ // Register $UsersID, $U_Password and redirect to file "login_success.php" $_SESSION['UsersID']=$result2[0]; $_SESSION['U_YearID']=$result2[1]; if($_SESSION['U_YearID']==1){ header("location:login_success.php"); exit; } if($_SESSION['U_YearID']==2){ header("location:login_success2.php"); exit; } if($_SESSION['U_YearID']==4){ header("location:login_success4.php"); exit; } } else { echo "Wrong Username or Password"; } } ?> YES!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! You my sir are a genius Thank you soooo much i can finally click solved!! Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/3/#findComment-1312390 Share on other sites More sharing options...
Drummin Posted January 30, 2012 Share Posted January 30, 2012 Now look into encoding your passwords. At the very least use MD5 on both your log in scripts and creating account scripts. $U_Password=MD5($U_Password); Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/3/#findComment-1312391 Share on other sites More sharing options...
jusjus7 Posted January 30, 2012 Author Share Posted January 30, 2012 Now look into encoding your passwords. At the very least use MD5 on both your log in scripts and creating account scripts. $U_Password=MD5($U_Password); ok i will look into that tomorrow as its 1am in the UK right now and i have been at this all day! lol thanks again!!! Quote Link to comment https://forums.phpfreaks.com/topic/255984-redirect-logging-in-users-to-different-pages/page/3/#findComment-1312392 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.