Jump to content

Archived

This topic is now archived and is closed to further replies.

redarrow

login two types of members to a correct page please help.

Recommended Posts

My code is below, I want to be able to setup for two types of users to login members/booking_member then the user goes to the correct page.


Am i doing it correct advance thank you.

Code example.

[code]
<? session_start();

if( $name && $password) {

$db=mysql_connect("localhost" ,"username","password");
mysql_select_bd("art",$db);
$query="SELECT * from members WHERE name='$name' AND password='$password');
$result=mysql_query($query);

if(mysql_num_rows($result) > 0)) {

$name=$name;

session_register["name"];

header("Location: http://members_page.php");
}

}else if( ! $name|| $password) {

echo"please use  all the form and the correct name and password"
}



if( $name && $password) {

$query="SELECT * from booking_members WHERE name='$name' AND password='$password');
$result=mysql_query($query);

if(mysql_num_rows($result) > 0)) {

$name=$name;

session_register["name"];

header("Location: http://booking_members_page.php/");
}

else if( ! $name|| $password) {

echo"please use all the form and the correct name and password"

}

?>
[/code]

Html form
[code]
<html>
<head>
<title>login page</title>
<body>
<h1>login please!</h1>

<form method="post" action="">
<br>
Username:
<br>
<input type="text" name="name">
<br>
Password:
<br>
<input type="pass" name="password">
<br>
<input type="submit" name="submit" value="Login">
<br>
</form>
</body>
</html>
[/code]

Share this post


Link to post
Share on other sites
Alright... a few issues:

1) you don't have to use session_register(). Just use $_SESSION['var_name'] = x;

2) }else if( ! $name|| $password) won't work. $name and $password are not boolean variables. And I assume you want to fail that if when $password is blank as well.... right now it passes if $password is true. And you never compare the database results to what is passed from the form. How do you think authentication works!?!?

Share this post


Link to post
Share on other sites
If I understand your question there are 2 types of memberships: level1 and level2

if the member is of level1 then after correct login s/he is redirected to
[a href=\"http://booking_members_page.php/\" target=\"_blank\"]http://booking_members_page.php/[/a]

and if s/he is from level 2 then the redirect will to to a different URL?

If that is the case, you need to add a colum in your database that will allow to store the membership level for each member (level1 and level 1).

During the login your query will have to retrieve both the membership level info and with:

if($row['membership']=='level1'){
header("Location: [a href=\"http://booking_members_page1.php/");\" target=\"_blank\"]http://booking_members_page1.php/");[/a]
}
else if($row['membership']=='level2'){
header("Location: [a href=\"http://booking_members_page1.php/");\" target=\"_blank\"]http://booking_members_page1.php/");[/a]
}







Share this post


Link to post
Share on other sites
[!--quoteo(post=371618:date=May 5 2006, 05:57 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ May 5 2006, 05:57 PM) [snapback]371618[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Alright... a few issues:

1) you don't have to use session_register(). Just use $_SESSION['var_name'] = x;

2) }else if( ! $name|| $password) won't work. $name and $password are not boolean variables. And I assume you want to fail that if when $password is blank as well.... right now it passes if $password is true. And you never compare the database results to what is passed from the form. How do you think authentication works!?!?
[/quote]


What about now ober.

[code]
<? session_start();

if( $name || $password) {


$db=mysql_connect("localhost" ,"username","password");
mysql_select_db("art",$db);
$query="SELECT * from members WHERE name='$name' AND password='$password');
$result=mysql_query($query);

if(mysql_num_rows($result) > 0)) {

$name=$name;

$_SESSION['name'] = $name;

header("Location: http://members_page.php");
}
}

if(mysql_num_rows($result) < 0)) {

echo"sorry acount does not exist please register!";

}

} else if (! $name || $password) {

echo " sorry please fill in all the form";

}

if( $name || $password) {


$query="SELECT * from booking_members WHERE name='$name' AND password='$password');
$result=mysql_query($query);

if(mysql_num_rows($result) > 0)) {

$name=$name;

$_SESSION['name'] = $name;

header("Location: http://booking_members_page.php");
}


if(mysql_num_rows($result) < 0)) {

echo"sorry acount does not exist please register!";

}

} else if (! $name || $password) {

echo " sorry please fill in all the form";

}
?>
[/code]

Html form
[code]
<html>
<head>
<title>login page</title>
<body>
<h1>login please!</h1>

<form method="post" action="">
<br>
Username:
<br>
<input type="text" name="name">
<br>
Password:
<br>
<input type="pass" name="password">
<br>
<input type="submit" name="submit" value="Login">
<br>
</form>
</body>
</html>
[/code]

Share this post


Link to post
Share on other sites
before you can chekc for the meber name you need to give your password and name fields a name..

than passthose name in the scrip as varieable and them check for the name as variable in the database..

$username = $_POST['username'];
$password = $_POST['password'];
$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password")

if the name and passward are in the database do the fetch array for any other string you might want or anything else you want and pass it as session variable..

session_register('username');
$_SESSION['username'] = $username;
session_register('password');
$_SESSION['password'] = $password;

Share this post


Link to post
Share on other sites
[!--sizeo:5--][span style=\"font-size:18pt;line-height:100%\"][!--/sizeo--]solved[!--sizec--][/span][!--/sizec--]

Share this post


Link to post
Share on other sites

×

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.