Jump to content

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.