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 Quote 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] Quote 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 :) Quote Link to comment https://forums.phpfreaks.com/topic/7713-phpmysql-id-redirect/#findComment-28141 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.