matt.sisto Posted May 4, 2009 Share Posted May 4, 2009 I have written an if statement, that I want to run should the the variables hold any value, but if they do not, and the else is run I have an error message however I just want it to continue to the next if: <?php session_start(); if (!isset($_SESSION['username'])) { header("Location: login.php"); exit(); } require "dbconn2.php"; $unit = $_POST['unit']; $service = $_POST['service']; $quantity = $_POST['quantity']; $con_id1 = $_POST['con_id1']; $con_id2 = $_POST['con_id2']; $con_id3 = $_POST['con_id3']; if ($con_id1 !=null){ $result = mysql_query("SELECT SUM(rate) FROM consultant WHERE con_id='$con_id1'"); if($result !=null){ $rate = mysql_result($result, 0); } else{ die ("Could not perform query1 $sql <br />".mysql_error()); } $result = mysql_query("SELECT SUM(fee) FROM rate_service WHERE service = '".$service."' AND unit ='".$unit."' AND rate='".$rate."'"); if($result !=null){ $fee = mysql_result($result, 0); } else{ die ("Could not perform query2 $sql <br />".mysql_error()); } $x = (int) $quantity; $y = (int) $fee; $eventFee1 = $y * $x; } if ($con_id2 !=null){ $result = mysql_query("SELECT SUM(rate) FROM consultant WHERE con_id='$con_id2'"); if($result !=null){ $rate = mysql_result($result, 0); } else{ die ("Could not perform query3 $sql <br />".mysql_error()); } $result = mysql_query("SELECT SUM(fee) FROM rate_service WHERE service = '".$service."' AND unit ='".$unit."' AND rate='".$rate."'"); if($result !=null){ $fee = mysql_result($result, 0); } else{ die ("Could not perform query4 $sql <br />".mysql_error()); } $x = (int) $quantity; $y = (int) $fee; $eventFee2 = $y * $x; } if ($con_id3 !=null){ $result = mysql_query("SELECT SUM(rate) FROM consultant WHERE con_id='$con_id3'"); if($result !=null){ $rate = mysql_result($result, 0); } else{ die ("Could not perform query5 $sql <br />".mysql_error()); } $result = mysql_query("SELECT SUM(fee) FROM rate_service WHERE service = '".$service."' AND unit ='".$unit."' AND rate='".$rate."'"); if($result !=null){ $fee = mysql_result($result, 0); } else{ die ("Could not perform query6 $sql <br />".mysql_error()); } $x = (int) $quantity; $y = (int) $fee; $eventFee3 = $y * $x; } else { die ("Could not perform query5 $sql <br />".mysql_error()); } $eventTotal = (int) $eventFee1 + (int) $eventFee2 + (int) $eventFee3; echo $eventTotal; ?> <html> <head> <title>Book</title> </head> <body> </body> </html> Any help appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/156780-solved-ending-my-if-statement-without-an-error-message/ Share on other sites More sharing options...
matt.sisto Posted May 4, 2009 Author Share Posted May 4, 2009 I don't want it to die if the value is null, I just want it to continue to the next if statement. Quote Link to comment https://forums.phpfreaks.com/topic/156780-solved-ending-my-if-statement-without-an-error-message/#findComment-825595 Share on other sites More sharing options...
the182guy Posted May 4, 2009 Share Posted May 4, 2009 You can just comment out the error message, or remove the ELSE part completely. Quote Link to comment https://forums.phpfreaks.com/topic/156780-solved-ending-my-if-statement-without-an-error-message/#findComment-825597 Share on other sites More sharing options...
matt.sisto Posted May 4, 2009 Author Share Posted May 4, 2009 At the moment it only works none of the variables con_id1 and con_id2 and con_id3 are null. Quote Link to comment https://forums.phpfreaks.com/topic/156780-solved-ending-my-if-statement-without-an-error-message/#findComment-825598 Share on other sites More sharing options...
matt.sisto Posted May 4, 2009 Author Share Posted May 4, 2009 Thanks I have sorted it now. I knew it would be simple. Still learning. <?php session_start(); if (!isset($_SESSION['username'])) { header("Location: login.php"); exit(); } require "dbconn2.php"; $unit = $_POST['unit']; $service = $_POST['service']; $quantity = $_POST['quantity']; $con_id1 = $_POST['con_id1']; $con_id2 = $_POST['con_id2']; $con_id3 = $_POST['con_id3']; if ($con_id1 !=null){ $result = mysql_query("SELECT SUM(rate) FROM consultant WHERE con_id='$con_id1'"); if($result !=null){ $rate = mysql_result($result, 0); } $result = mysql_query("SELECT SUM(fee) FROM rate_service WHERE service = '".$service."' AND unit ='".$unit."' AND rate='".$rate."'"); if($result !=null){ $fee = mysql_result($result, 0); } $x = (int) $quantity; $y = (int) $fee; $eventFee1 = $y * $x; } if ($con_id2 !=null){ $result = mysql_query("SELECT SUM(rate) FROM consultant WHERE con_id='$con_id2'"); if($result !=null){ $rate = mysql_result($result, 0); } $result = mysql_query("SELECT SUM(fee) FROM rate_service WHERE service = '".$service."' AND unit ='".$unit."' AND rate='".$rate."'"); if($result !=null){ $fee = mysql_result($result, 0); } $x = (int) $quantity; $y = (int) $fee; $eventFee2 = $y * $x; } if ($con_id3 !=null){ $result = mysql_query("SELECT SUM(rate) FROM consultant WHERE con_id='$con_id3'"); if($result !=null){ $rate = mysql_result($result, 0); } $result = mysql_query("SELECT SUM(fee) FROM rate_service WHERE service = '".$service."' AND unit ='".$unit."' AND rate='".$rate."'"); if($result !=null){ $fee = mysql_result($result, 0); } $x = (int) $quantity; $y = (int) $fee; $eventFee3 = $y * $x; } $eventTotal = (int) $eventFee1 + (int) $eventFee2 + (int) $eventFee3; echo $eventTotal; ?> <html> <head> <title>Book</title> </head> <body> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/156780-solved-ending-my-if-statement-without-an-error-message/#findComment-825603 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.