w00kie Posted April 18, 2006 Share Posted April 18, 2006 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 redirectsthanks in advance Link to comment https://forums.phpfreaks.com/topic/7713-phpmysql-id-redirect/ Share on other sites More sharing options...
GingerRobot Posted April 18, 2006 Share Posted April 18, 2006 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] Link to comment https://forums.phpfreaks.com/topic/7713-phpmysql-id-redirect/#findComment-28137 Share on other sites More sharing options...
w00kie Posted April 18, 2006 Author Share Posted April 18, 2006 [!--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 :) Link to comment https://forums.phpfreaks.com/topic/7713-phpmysql-id-redirect/#findComment-28141 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.