Dane Posted November 3, 2007 Share Posted November 3, 2007 Hey guys, I'm not really sure how to write this bit of code so im going to explain the best i can. Basically i want to grab mail_id from mail.php?mail_id=1 if(!empty($_GET['mail_id'])){ $mail_id = $_GET['mail_id']; if(mysql_num_rows($sql)==1){ $col = mysql_fetch_array($sql); } Say for instance mail_id=1 is inside the database with the mail information correct. But value mail_id=2 is not inside the database. When i goto mail.php?mail_id=2 in my browser i want it to come up with an error saying "no mail" or something like that. How would be the best way to go about this bit of coding? Thanks Dane Quote Link to comment https://forums.phpfreaks.com/topic/75917-solved-stuck-a-little/ Share on other sites More sharing options...
kratsg Posted November 3, 2007 Share Posted November 3, 2007 I love simple questions like this :-D Here ya go. <?php if(isset($_GET['mail_id'])){//if the mail_id is in the url, let's check it if(!empty($_GET['mail_id']) && is_numeric($_GET['mail_id'])){//it's not empty and it's a number $mail_id = $_GET['mail_id']; $query = "SELECT column1,column2,column3,etc FROM table_name WHERE `mail_id` = '$mail_id' LIMIT 1";//set-up query with a limit of 1 to return only 1 row maximum if(!mysql_num_rows(mysql_query($query))){//1 = true, 0 = false die("I'm sorry, the mail id that was entered is incorrect."); } //if we got to this point, there was data returned $row = mysql_fetch_array(mysql_query($query)); $column1 = $row['column1']; $column2 = $row['column2']; $column3 = $row['column3']; $etc = $row['etc']; } else {//$_GET['mail_id'] was either: empty/null or not a number die("I'm sorry, the mail_id inputted was an incorrect format or empty."); } } else {//there's no mail_id in the url //output the form } ?> Quote Link to comment https://forums.phpfreaks.com/topic/75917-solved-stuck-a-little/#findComment-384265 Share on other sites More sharing options...
Daney11 Posted November 3, 2007 Share Posted November 3, 2007 awesome, works a treat, thanks Quote Link to comment https://forums.phpfreaks.com/topic/75917-solved-stuck-a-little/#findComment-384292 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.