Jump to content

multiple user login


mariam

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.