mariam Posted June 20, 2011 Share Posted June 20, 2011 i have written a code for checking username and password, and then directing to a specific profile page w.r.t the username entered.. the password checking works fine but it directs the page to only one profile irrespective of the username entered.. below is my code <?php //$mysql_host = "mysql14.000webhost.com"; //$mysql_database = "a3907930_mehreen"; //$mysql_user = "a3907930_root"; //$mysql_password = "aaaAAA111"; $host="mysql14.000webhost.com"; // Host name $username="a3907930_root"; // Mysql username $password="aaaAAA111"; // Mysql password $db_name="a3907930_mehreen"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect($host, $username, $password)or die("cannot connect"); mysql_select_db($db_name)or die("cannot select DB"); // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); if ($myusername='mehreen') header ("location:mehreen_profile.php"); elseif ($myusername='mariam') header ("location:mariam_profile.php"); else header ("location:login_page.html"); } else { header("location:invalidpassword.html"); } ?> could u plz help! Link to comment https://forums.phpfreaks.com/topic/239895-multiple-user-login/ Share on other sites More sharing options...
HDFilmMaker2112 Posted June 20, 2011 Share Posted June 20, 2011 i have written a code for checking username and password, and then directing to a specific profile page w.r.t the username entered.. the password checking works fine but it directs the page to only one profile irrespective of the username entered.. below is my code <?php //$mysql_host = "mysql14.000webhost.com"; //$mysql_database = "a3907930_mehreen"; //$mysql_user = "a3907930_root"; //$mysql_password = "aaaAAA111"; $host="mysql14.000webhost.com"; // Host name $username="a3907930_root"; // Mysql username $password="aaaAAA111"; // Mysql password $db_name="a3907930_mehreen"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect($host, $username, $password)or die("cannot connect"); mysql_select_db($db_name)or die("cannot select DB"); // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); if ($myusername='mehreen') header ("location:mehreen_profile.php"); elseif ($myusername='mariam') header ("location:mariam_profile.php"); else header ("location:login_page.html"); } else { header("location:invalidpassword.html"); } ?> could u please help! My first suggestion is to always use {} brackets on all if/elseif/else statements. Also try adding dot slash "./" to all of the location header redirects, and change the lowercase l in location to a capital L. ie; header ("Location: ./login_page.html"); Lastly, your if/elseif statements have one = sign... when comparing (as you are in an if/elseif statement) it must be two equal signs. With one equal sign you're declaring a variable, and thus the first if statement will always be true, because you're declaring it to be true right in the statement. Link to comment https://forums.phpfreaks.com/topic/239895-multiple-user-login/#findComment-1232246 Share on other sites More sharing options...
mariam Posted June 20, 2011 Author Share Posted June 20, 2011 its working now with "==' insted of '=" in if statment thanx! Link to comment https://forums.phpfreaks.com/topic/239895-multiple-user-login/#findComment-1232284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.