erme Posted January 19, 2010 Share Posted January 19, 2010 Hi, I currently have something like this: /company.php?county=devon but if, say, a user manually puts something like this in /company.php?county=devvvon I want it to display a message (possibly re-direct to another page) saying "County does not exist" Quote Link to comment https://forums.phpfreaks.com/topic/189040-simple-error-message-if-not-in-database/ Share on other sites More sharing options...
kickstart Posted January 19, 2010 Share Posted January 19, 2010 Hi Should be easy to do, but will largely depend on your existing page. You could check a database of counties and when the mysql_num_rows() is 0 put out a message or use a header redirect (eg header('Location:../ListCounties.php');). Not really a MySQL issue though. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/189040-simple-error-message-if-not-in-database/#findComment-998133 Share on other sites More sharing options...
erme Posted January 19, 2010 Author Share Posted January 19, 2010 Thanks for the prompt reply. Sorry didn't mean to post here. Will repost it in PHP section. I'm very new to PHP, how can I check the counties in the database? Quote Link to comment https://forums.phpfreaks.com/topic/189040-simple-error-message-if-not-in-database/#findComment-998135 Share on other sites More sharing options...
kickstart Posted January 19, 2010 Share Posted January 19, 2010 Hi It is likely to be simple but would need more info on your current system / database tables to say. In simple terms:- $sql = "SELECT County FROM CountiesTable WHERE CountyName = '".mysql_real_escape_string($_REQUEST['county'])."'"; $result = mysql_query($sql,$conn) or die(mysql_error()." $sql"); if ($row = mysql_fetch_array($result)) { // County found so all OK. } else { header('Location:../ListCounties.php'); } All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/189040-simple-error-message-if-not-in-database/#findComment-998143 Share on other sites More sharing options...
erme Posted January 19, 2010 Author Share Posted January 19, 2010 Thanks Keith, I managed to get it working with this $q = mysql_query("SELECT * FROM table WHERE name = '$name'"); $n = mysql_num_rows($q); if($n > 0){ echo $name; }else{ echo $name." not found."; } Quote Link to comment https://forums.phpfreaks.com/topic/189040-simple-error-message-if-not-in-database/#findComment-998149 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.