I'm relatively new to coding.
Here are a couple links I've used:
What I'm trying to do is load a html table once an option is selected in the form. Using ajax append the value of the option to the 'formscript.php?n=' URL. Then use that value to load the correct rows matching that value.
When the table is being populated in a while loop I've put some if statements in for when I want the queries to be executed; the problem is that it will execute the $uplift but won't execute the $delete_outdated and neither will it populate the table.
How can I get the $uplift and $delete_outdated to execute and populate the table? Or is there a better way to do this correctly?
php script:
$area = $_GET['a'];
$stmt = $pdo->prepare("SELECT * FROM stage1 WHERE area = :area");
$stmt->bindParam(':area', $area, PDO::PARAM_STR);
$stmt->execute();
$sql1 = "INSERT INTO stage2 SELECT * FROM stage1 WHERE target_date < CURRENT_DATE(); AND id = :id";
$uplift = $pdo->prepare($sql1);
$uplift->bindParam(':id', $id, PDO::PARAM_STR);
$sql2 = "DELETE FROM stage1 WHERE target_date < CURRENT_DATE() AND id = :id";
$delete_outdated = $pdo->prepare($sql2);
$delete_outdated->bindParam(':id', $id, PDO::PARAM_STR);
$sql3 = "INSERT INTO originator SELECT * FROM stage1 WHERE completion=100;";
$signoff = $pdo->prepare($sql3);
$sql4 = "DELETE FROM stage1 WHERE completion=100; ";
$delete_completions = $pdo->prepare($sql4);
echo "<table'><thead><tr><th scope='col'>ID</th><th scope='col'>Area</th><th scope='col'>Target Date</th><th scope='col'>Completion</th></tr></thead><tbody>";
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$target_date = $row['target_date'];
$id = $row['id'];
if($target_date < date('Y-m-d')){
$uplift->execute();
// $uplift->debugDumpParams();
if($affected1 = $uplift->rowCount() == 1){
$delete_outdated->execute();
// $delete_outdated->debugDumpParams();
};
};
if($row['completion'] == 100){
$signoff->execute();
if($affected2 = $signoff->rowCount() == 1){
$delete_completions->execute();
};
};
echo "<tr>";
echo "<th scope='row'>" . $row['id'] . "</td>";
echo "<td>" . $row['area'] . "</td>";
echo "<td>" . $row['target_date'] . "</td>";
echo "<td>" . $row['completion'] . "%</td>";
echo "</tr>";
};
echo "</tbody></table>";