Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 05 May 2006 - 05:50 PM

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.

<? 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"

}

?>

Html form
<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>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 05 May 2006 - 05:57 PM

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

Info: PHP Manual


#3 onepixel

onepixel
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 05 May 2006 - 06:06 PM

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








<a href="http://www.saheltech.com">PHP Programming - WordPress Blog Customization</a>

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 05 May 2006 - 06:10 PM

[!--quoteo(post=371618:date=May 5 2006, 05:57 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ May 5 2006, 05:57 PM) View Post[/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.

<? 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";

}
?>

Html form
<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>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 05 May 2006 - 06:18 PM

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;



#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 06 May 2006 - 05:17 AM

[!--sizeo:5--][span style=\"font-size:18pt;line-height:100%\"][!--/sizeo--]solved[!--sizec--][/span][!--/sizec--]
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users