Jump to content

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]
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!?!?
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]
}







[!--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]
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;

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.