I am very new to coding so please go gently...
I'm creating an admin page with list of accounts which require validation. All I require is for the value in the 'validated' column in the DB to change from 0 to 1 when the button is clicked. The problem is that it triggers the same thing for all the other returned results in the loop, who each have their own buttons, rather than just for that particular iteration of the loop. Any help would be greatly appreciated. Code looks as follows currently :
<?php
$sql ="SELECT customer.First_Name, customer.Last_Name, account.account_no, account.client_id, customer.username
FROM customer
INNER JOIN account
ON customer.customer_id=account.client_id
WHERE validated = 0";
$tobe_validated = $dbh->query($sql);
foreach ($tobe_validated as $row) {
//creating variable for account number to put in query
$clientid=$row["client_id"];
echo "<div class='valid_name_btn'>";
echo "<form method='post'><input type='submit' class='btn btn-outline-primary' value ='Validate' name='validate' id='validate'></input></form>";
echo "<div class='valid_name'>"; //div for name
echo $row["First_Name"] . " " . $row["Last_Name"]." - Account No. ". $row["account_no"]."<br/>"; //show name and account number of client
echo "</div>";
echo "</div>";
// query to change validated in customer table to 1
$sql ="UPDATE customer SET validated = 1 WHERE customer_id = '$clientid'";
// validate account when button is clicked
if(isset($_POST['validate'])) {
$dbh->query($sql);
}
}
$clientidupon submit?