jimmyp3016 Posted July 20, 2006 Share Posted July 20, 2006 I have a page that loads a persons data from a sql database and puts it into the page. I need to know how to check the database, and if the user is not in it then redirect to a different page. This is prob easy to do, im just new at php and sql. any help would be great. Quote Link to comment https://forums.phpfreaks.com/topic/15158-quick-question/ Share on other sites More sharing options...
trq Posted July 20, 2006 Share Posted July 20, 2006 [quote]I have a page that loads a persons data from a sql database and puts it into the page[/quote]Which persons data? How does it know who to load? Quote Link to comment https://forums.phpfreaks.com/topic/15158-quick-question/#findComment-61063 Share on other sites More sharing options...
ChaosXero Posted July 20, 2006 Share Posted July 20, 2006 I'd need to know your table info to write a script but here is an outline (Look in the FAQ for database help):Connect to DBSelct DBLook in users for 'user'If no results header('location: redirected page') Quote Link to comment https://forums.phpfreaks.com/topic/15158-quick-question/#findComment-61064 Share on other sites More sharing options...
jimmyp3016 Posted July 20, 2006 Author Share Posted July 20, 2006 here is my code:[code]$user = $_GET['usr'];$db = @mysql_connect("$localhost", "$databaseuser", "$databasepasswd");@mysql_select_db("$databasename",$db);$sql = "SELECT * FROM table WHERE user='$user'";$result = mysql_query($sql,$db);if (mysql_num_rows($result) != 0) { $firstname = mysql_result($result, 0, "firstname"); $lastname = mysql_result($result, 0, "lastname");}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15158-quick-question/#findComment-61065 Share on other sites More sharing options...
trq Posted July 20, 2006 Share Posted July 20, 2006 [code=php:0]$user = $_GET['usr'];$db = @mysql_connect("$localhost", "$databaseuser", "$databasepasswd");@mysql_select_db("$databasename",$db);$sql = "SELECT * FROM table WHERE user='$user'";$result = mysql_query($sql,$db);if (mysql_num_rows($result) != 0) { $firstname = mysql_result($result, 0, "firstname"); $lastname = mysql_result($result, 0, "lastname");} else { header("Location: usernotfound.php"); // <--- put the page you wish to direct to here.}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15158-quick-question/#findComment-61066 Share on other sites More sharing options...
Caesar Posted July 20, 2006 Share Posted July 20, 2006 It's not as simple as just throwing an answer at you.1. You need to know what table to lookup.2. How are users handles in your curent script? What are you using as criteria? Userid? Username?3. You then need a conditional statement that executes your redirection, based on the results.4. What method is your current code using? Is it using OOP? The database query might look diferent if that's the case.You have any example code?http://www.php.net <--Very helpful site. Use it. Quote Link to comment https://forums.phpfreaks.com/topic/15158-quick-question/#findComment-61067 Share on other sites More sharing options...
jimmyp3016 Posted July 20, 2006 Author Share Posted July 20, 2006 Thorpe,You are truly a Guru! Thank you! It worked. Quote Link to comment https://forums.phpfreaks.com/topic/15158-quick-question/#findComment-61073 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.