943,799 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1122
  • PHP RSS
Sep 8th, 2008
0

Help with different users login and directing to location

Expand 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


PHP Syntax (Toggle Plain Text)
  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. ?>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bdcd is offline Offline
9 posts
since Jul 2008
Sep 8th, 2008
0

Re: Help with different users login and directing to location

Hi bdcd,

Click to Expand / Collapse  Quote originally posted by bdcd ...
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):
php Syntax (Toggle Plain Text)
  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
Reputation Points: 15
Solved Threads: 1
Newbie Poster
tgbyhn is offline Offline
8 posts
since Sep 2008
Sep 8th, 2008
0

Re: Help with different users login and directing to location

Thank you it works now, thanks for the link as well.
Last edited by bdcd; Sep 8th, 2008 at 2:36 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bdcd is offline Offline
9 posts
since Jul 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: creating RSS for forum
Next Thread in PHP Forum Timeline: Trying to display an image rom mysql: whats wrong





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC