DanDewey Posted March 8, 2023 Share Posted March 8, 2023 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')"); } Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 8, 2023 Share Posted March 8, 2023 These statements are incorrect - I've shown you one. Look for similar mistakes. if ($MileageQty = 0){ return; You are not testing anything. You are making an assignment. Quote Link to comment Share on other sites More sharing options...
Solution DanDewey Posted March 8, 2023 Author Solution Share Posted March 8, 2023 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')"); } } Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 8, 2023 Share Posted March 8, 2023 (edited) 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 March 8, 2023 by ginerjm 1 Quote Link to comment 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.