Jump to content

Help with PHP Skipping If Statement


DanDewey
Go to solution Solved by DanDewey,

Recommended Posts

Hi All, I'm doing a follow-up post from previous help here if possible.  Using WordPress/Gravity Forms I'm entering 1 line of data into a MySQL database for each of the 4 functions, the first function runs perfectly but functions 2-4 run on an IF query and the issue I'm seeing is that all three functions will trigger if only one of them meet criteria they are not working independently of each other.

Ideally, it should simply be Fucntion1(beta_pay) triggers every time, and then fucntions2-5 trigger independently only if they meet the criteria on their own and not a one for all scenario.

 

Any input would be great I've tried various scenarios

 

Function 1 is beta_pay which runs automatically every time which is correct

add_action("gform_after_submission_123", "beta_pay", 10, 2);
function beta_pay($entry, $form){
    
$Name = $entry["1"];
$Service = $entry["3"];
$Value = $entry["4"];
$Qty = $entry["11"];

$con=mysqli_connect("");
mysqli_query($con,"INSERT INTO beta_pay (Name,Type,Value,Qty) VALUES ('$Name','$Service','$Value','$Qty')");
}

 

Function 2 is Mileage which runs on an IF statement and works fine as long as Functions 2-5 meet requirements otherwise it posts data regardless

add_action("gform_after_submission_123", "Mileage", 10, 2);
function Mileage($entry, $form){

  $MileageQty = $entry["5"];
  if ($MileageQty = 0){
  	return;
  }
  
  $Name = $entry["1"];
  $Service = "Fixed-Milage";
  $MileageRate = $entry["10"];
  $MileageQty = $entry["5"];

  $con=mysqli_connect("");
  mysqli_query($con,"INSERT INTO beta_pay (Name,Type,Value,Qty) VALUES ('$Name','$Service','$MileageRate','$MileageQty')");
}

 

Function 3 is Away which runs on an IF statement and works fine as long as Functions 2-5 meet requirements otherwise it posts data regardless

add_action("gform_after_submission_123", "Away", 10, 2);
function Away($entry, $form){
  $AwayQty = $entry["20"];
  if ($AwayQty = 0){
  	return;
  }
  
  $Name = $entry["1"];
  $Service = "Fixed-Away Payment";
  $AwayRate = $entry["19"];
  $AwayQty = $entry["20"];

  $con=mysqli_connect("");
  mysqli_query($con,"INSERT INTO beta_pay (Name,Type,Value,Qty) VALUES ('$Name','$Service','$AwayRate','$AwayQty')");
}

Function 4 is CC which runs on an IF statement and works fine as long as Functions 2-5 meet requirements otherwise it posts data regardless

add_action("gform_after_submission_123", "CC", 10, 2);
function CC($entry, $form){
  $CCQty = $entry["13"];
  if ($CCQty = 0){
  	return;
  }
  
  $Name = $entry["1"];
  $Service = "Fixed-Congestion Charge";
  $CCRate = $entry["16"];
  $CCQty = $entry["13"];

  $con=mysqli_connect("");
  mysqli_query($con,"INSERT INTO beta_pay (Name,Type,Value,Qty) VALUES ('$Name','$Service','$CCRate','$CCQty')");
}

Function 5 is Toll which runs on an IF statement and works fine as long as Functions 2-5 meet requirements otherwise it posts data regardless

add_action("gform_after_submission_123", "Toll", 10, 2);
function Toll($entry, $form){
  $TollQty = $entry["15"];
  if ($TollQty = 0){
  	return;
  }
  
  $Name = $entry["1"];
  $Service = "Fixed-Toll Crossing";
  $TollRate = $entry["17"];
  $TollQty = $entry["15"];

  $con=mysqli_connect("");
  mysqli_query($con,"INSERT INTO beta_pay (Name,Type,Value,Qty) VALUES ('$Name','$Service','$TollRate','$TollQty')");
}

 

Link to comment
Share on other sites

  • Solution

So I've managed to solve myself by changing functions 2-5 to the following and now all functions are working independently

 

add_action("gform_after_submission_123", "CC", 10, 2);
function CC($entry, $form){
  $con=mysqli_connect("");
  $CCQty = $entry["13"];
  
  if ($CCQty > 0){
  	
  $Name = $entry["1"];
  $Service = "Fixed-Congestion Charge";
  $CCRate = $entry["16"];
  $CCQty = $entry["13"];

  mysqli_query($con,"INSERT INTO beta_pay (Name,Type,Value,Qty) VALUES ('$Name','$Service','$CCRate','$CCQty')");
  }
}

 

Link to comment
Share on other sites

You do see what you were doing wrong before, yes?  Here you simply swapped out an incorrect if statement for a different one that did a proper test.  Should have used  if ($CCQry == 0) not = 0

Edited by ginerjm
  • Like 1
Link to comment
Share on other sites

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.