Jump to content


Photo

PHP/MYSQL ID REDIRECT


  • Please log in to reply
2 replies to this topic

#1 w00kie

w00kie
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 18 April 2006 - 12:41 PM

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





#2 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 18 April 2006 - 01:04 PM

Use mysql_num_rows();

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


#3 w00kie

w00kie
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 18 April 2006 - 01:10 PM

[!--quoteo(post=365978:date=Apr 18 2006, 08:04 AM:name=GingerRobot)--][div class=\'quotetop\']QUOTE(GingerRobot @ Apr 18 2006, 08:04 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Use mysql_num_rows();

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

thank you ever so much :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users