I have a PHP script to post the following data to add-rma-process.php after submission:
$_POST['rmanumber']
$_POST['parent']
$_POST['qty']
However, there are also other fields which are to be posted but will depend on the $_POST['qty'] variable. Say, the $_POST['qty'] = 5 then I will have $_POST['pn1'], $_POST['sn1'], $_POST['rm1'] up to $_POST['pn5'], $_POST['sn5'], $_POST['rm5']. I think you guys get the logic.
Once add-rma-process.php receives these data, I am doing this:
require("common.php");
for($i=0; $i<$_POST['qty']; $i++) {
$count = $i+1; // to start with 1 instead of 0
$query = "INSERT INTO rmadb (rmanumber, parent, childpn, childsn, remarks, user, date) VALUES (:rmanumber, :parent, :childpn, :childsn, :remarks, :user, NOW())";
$query_params = array(
":rmanumber" => $_POST['rmanumber'],
":parent" => $_POST['parent'],
":childpn" => $_POST['pn$count'],
":childsn" => $_POST['sn$count'],
":remarks" => $_POST['rm$count'],
":user" => $_SESSION['user']['fname']." ".$_SESSION['user']['lname']
);
try {
$stmt = $db->prepare($query);
$res = $stmt->execute($query_params);
} catch(PDOException $ex) {
die("Failed to run query: " . $ex->getMessage());
}
}
What I was trying to do is do a for loop to execute the query until the condition is met but it is not working. What seems to be wrong?
rm[],sn[],pn[]. This will cause all the input to be compiled into arrays$_POST['rm'],$_POST['sn'],$_POST['pn']that would be much easier to work with in PHP.