Jump to content

[SOLVED] ending my if statement without an error message.


matt.sisto

Recommended Posts

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.  8)

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.