Help with different users login and directing to location

Thread Solved

Join Date: Jul 2008
Posts: 9
Reputation: bdcd is an unknown quantity at this point 
Solved Threads: 0
bdcd bdcd is offline Offline
Newbie Poster

Help with different users login and directing to location

 
0
  #1
Sep 8th, 2008
So I want the code to allow the user to login and then direct them to their page, I'm just not sure how I can do that. Here's the table and code I have, is there a way to make "header("location:/instacp.htm");" pull the location from the table in the database?

Table:
id username password location
1 12345 123456 /instacp.htm


  1. <?php
  2. $host="localhost";
  3. $username="blaa";
  4. $password="blaa";
  5. $db_name="blaa_members";
  6. $tbl_name="members";
  7.  
  8.  
  9. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  10. mysql_select_db("$db_name")or die("cannot select DB");
  11.  
  12.  
  13. $myusername=$_POST['myusername'];
  14. $mypassword=$_POST['mypassword'];
  15.  
  16.  
  17. $myusername = stripslashes($myusername);
  18. $mypassword = stripslashes($mypassword);
  19. $myusername = mysql_real_escape_string($myusername);
  20. $mypassword = mysql_real_escape_string($mypassword);
  21.  
  22. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  23. $result=mysql_query($sql);
  24.  
  25.  
  26. $count=mysql_num_rows($result);
  27.  
  28.  
  29. if($count==1){
  30. session_register("myusername");
  31. session_register("mypassword");
  32. header("location:/instacp.htm");
  33. }
  34. else {
  35. echo "Wrong Username or Password";
  36. }
  37. ?>
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 8
Reputation: tgbyhn is an unknown quantity at this point 
Solved Threads: 1
tgbyhn tgbyhn is offline Offline
Newbie Poster

Re: Help with different users login and directing to location

 
0
  #2
Sep 8th, 2008
Hi bdcd,

Originally Posted by bdcd View Post
So I want the code to allow the user to login and then direct them to their page, I'm just not sure how I can do that. Here's the table and code I have, is there a way to make "header("location:/instacp.htm");" pull the location from the table in the database?

Table:
id username password location
1 12345 123456 /instacp.htm
This should do the trick (note: this code is untested):
  1. <?php
  2. $host="localhost";
  3. $username="blaa";
  4. $password="blaa";
  5. $db_name="blaa_members";
  6. $tbl_name="members";
  7.  
  8.  
  9. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  10. mysql_select_db("$db_name")or die("cannot select DB");
  11.  
  12.  
  13. $myusername=$_POST['myusername'];
  14. $mypassword=$_POST['mypassword'];
  15.  
  16.  
  17. $myusername = stripslashes($myusername);
  18. $mypassword = stripslashes($mypassword);
  19. $myusername = mysql_real_escape_string($myusername);
  20. $mypassword = mysql_real_escape_string($mypassword);
  21.  
  22. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  23. $result=mysql_query($sql);
  24.  
  25. $row=mysql_fetch_assoc($result);
  26.  
  27. if($row!=false){
  28. session_register("myusername");
  29. session_register("mypassword");
  30. header("location: ".$row['location']);
  31. }
  32. else {
  33. echo "Wrong Username or Password";
  34. }
  35. ?>

More information on using mysql_fetch_assoc() can be found here - http://www.php.net/manual/en/functio...etch-assoc.php

Adnan
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 9
Reputation: bdcd is an unknown quantity at this point 
Solved Threads: 0
bdcd bdcd is offline Offline
Newbie Poster

Re: Help with different users login and directing to location

 
0
  #3
Sep 8th, 2008
Thank you it works now, thanks for the link as well.
Last edited by bdcd; Sep 8th, 2008 at 2:36 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC