| | |
Help with different users login and directing to location
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jul 2008
Posts: 9
Reputation:
Solved Threads: 0
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
Table:
id username password location
1 12345 123456 /instacp.htm
PHP Syntax (Toggle Plain Text)
<?php $host="localhost"; $username="blaa"; $password="blaa"; $db_name="blaa_members"; $tbl_name="members"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("myusername"); session_register("mypassword"); header("location:/instacp.htm"); } else { echo "Wrong Username or Password"; } ?>
•
•
Join Date: Sep 2008
Posts: 8
Reputation:
Solved Threads: 1
Hi bdcd,
This should do the trick (note: this code is untested):
More information on using mysql_fetch_assoc() can be found here - http://www.php.net/manual/en/functio...etch-assoc.php
Adnan
•
•
•
•
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)
<?php $host="localhost"; $username="blaa"; $password="blaa"; $db_name="blaa_members"; $tbl_name="members"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); $row=mysql_fetch_assoc($result); if($row!=false){ session_register("myusername"); session_register("mypassword"); header("location: ".$row['location']); } else { echo "Wrong Username or Password"; } ?>
More information on using mysql_fetch_assoc() can be found here - http://www.php.net/manual/en/functio...etch-assoc.php
Adnan
![]() |
Other Threads in the PHP Forum
- Previous Thread: How to create RSS Feed using php
- Next Thread: Trying to display an image rom mysql: whats wrong
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code codingproblem cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select send server sessions sms snippet soap source space speed sql static structure syntax system table tutorial up-to-date update upload url validation validator variable video web wordpress xml youtube





