dhimok Posted April 6, 2007 Share Posted April 6, 2007 Hello, I have a question if u might help me. I want to redirect to error page if trying to enter a page or article where id does not exist or is deleted. Let s say that the last record is 30 and if someone tries to abuse the site and enters ?c=60. The db query of course does not find any records. So how can I query the database and send them somewhere else if this happens? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/45885-solved-how-to-query-database-if/ Share on other sites More sharing options...
pocobueno1388 Posted April 6, 2007 Share Posted April 6, 2007 You just check to see if what they entered in the URL is fixed or not... <?php $c = $_GET['c']; $sql = mysql_query("SELECT col1, col2 FROM table WHERE c='$c'"): if (mysql_num_rows($sql) <= 0){ //redirect them } else { //display page information } ?> Link to comment https://forums.phpfreaks.com/topic/45885-solved-how-to-query-database-if/#findComment-222902 Share on other sites More sharing options...
dhimok Posted April 6, 2007 Author Share Posted April 6, 2007 well I used this one. It works well, just wonder if its good enough $sql = "SELECT * FROM table WHERE id = '" . $_GET['c'] . "'"; $res = dbQuery($sql) or die(mysql_error()); if(dbNumRows($res) == 0) header("location: error_page.html"); Link to comment https://forums.phpfreaks.com/topic/45885-solved-how-to-query-database-if/#findComment-222904 Share on other sites More sharing options...
boo_lolly Posted April 6, 2007 Share Posted April 6, 2007 after you declare your query, but before you print your results, place this piece of code in there: if(mysql_num_rows($query) < 1){ header('Location: http://www.your_domain/') } Link to comment https://forums.phpfreaks.com/topic/45885-solved-how-to-query-database-if/#findComment-222905 Share on other sites More sharing options...
dhimok Posted April 6, 2007 Author Share Posted April 6, 2007 Thats what I thought, thank you Link to comment https://forums.phpfreaks.com/topic/45885-solved-how-to-query-database-if/#findComment-222907 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.