Jump to content

Archived

This topic is now archived and is closed to further replies.

w00kie

PHP/MYSQL ID REDIRECT

Recommended Posts

Hi, I have MYSQL Rows in a table for instance :-

[a href=\"http://localhost/description?id=1\" target=\"_blank\"]http://localhost/description?id=1[/a]

now, this is fine. But what i want to do is, when a user enters an INVALID ID, which isn't a row in the MYSQL table to redirect to a different page. Or give an echo saying, this is ID is invalid.

so if someone enters [a href=\"http://localhost/description?id=09340350305035\" target=\"_blank\"]http://localhost/description?id=09340350305035[/a]

and that ID doesn't exist, it redirects

thanks in advance



Share this post


Link to post
Share on other sites
Use mysql_num_rows();

[code]
$sql = "SELECT * FROM `fieldname` WHERE `id`='$id'";
$result = mysql_query($sql);
$num = mysql_num_rows($result)
if($num < 1){
header("location:errorpage.php");
exit;
}
[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=365978:date=Apr 18 2006, 08:04 AM:name=GingerRobot)--][div class=\'quotetop\']QUOTE(GingerRobot @ Apr 18 2006, 08:04 AM) [snapback]365978[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Use mysql_num_rows();

[code]
$sql = "SELECT * FROM `fieldname` WHERE `id`='$id'";
$result = mysql_query($sql);
$num = mysql_num_rows($result)
if($num < 1){
header("location:errorpage.php");
exit;
}
[/code]
[/quote]

thank you ever so much :)

Share this post


Link to post
Share on other sites

×

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.