Jump to content

Quick Question


jimmyp3016

Recommended Posts

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.
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.