So, thank you all for your support here, i am now able to submit this large form successfully.
The submission code is as follows.
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if (!isset($_SESSION['user_name'])){
header("location: index.php");
}
include '../_includes/dbconn.php';
if ($_SERVER['REQUEST_METHOD']=='POST') {
$jobId = $_SESSION['current_job_id'];
$qty = $_POST['equipmentQty'];
// prepare insert query
$stmt = $conn->prepare("INSERT INTO ssm_equipment_order (job_id, equipment_id, equipment_quantity) VALUES (?,?,?) ");
foreach ($_POST['equipmentId'] as $k => $eid) {
if ($qty[$k] > 0) {
// $data = [$jobId, $eid, $qty[$k] ] ;
$stmt->bind_param("sss", $jobId, $eid, $qty[$k]);
$stmt->execute();
}
}
}
header("location: ../order-equipment.php");
My issue now is that when this page loads, it needs to get the information out of the database that builds the large form and fill the inputs with the quantities that were submitted before.
I have written the following:
<?php
include '_includes/dbconn.php';
$current_job_id = $_SESSION['current_job_id'];
$sql = "SELECT * FROM ssm_equipment_order where job_id = $current_job_id";
if ($result = mysqli_query($conn, $sql)){
if(mysqli_num_rows($result)>0){
$sql = "SELECT * FROM ssm_equipment";
if ($result = mysqli_query($conn, $sql)){
if(mysqli_num_rows($result)>0){
echo "<form method='post' action='actions/submit-equipment-order-action.php' id='equipmentOrderForm'>";
echo "<div class='input-group mt-3 mb-3'>";
echo "<div class='input-group-prepend'>";
echo "<span class='input-group-text'>Search (alt/option+s)</span>";
echo "</div>";
echo "<input id='equipmentTableSearch' onkeyup='searchEquipmentTable()' type='text' class='form-control' placeholder='Plates...Soup Spoon...Red Wine Glass...'>";
echo "<button type='submit' name='equipment_submit_button' class='btn btn-primary'>Submit</button'>";
echo "</div>";
echo "<table id='equipmentTable' class='mt-3 table table-striped table-hover table-bordered'>";
echo "<thead>";
echo "<tr class='text-center'><th>Equipment</th><th>Quantity</th></tr>";
echo "</thead>";
echo "<tbody>";
$current_job_id = $_SESSION['current_job_id'];
$sql2 = "SELECT * FROM ssm_equipment_order WHERE job_id = $current_job_id";
$result2 = mysqli_query($conn, $sql2);
while ($row2 = mysqli_fetch_array($result2)){ echo "XX "; }
while ($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td style='width:70%;'>".$row['equipment_name']."</td>";
echo "<input type='hidden' name='equipmentId[]' value='".$row['equipment_id']."'>";
echo "<td class='text-center'><input name='equipmentQty[]' class='eqQty text-center up' type='text'></td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
echo "</form>";
}
}
}else{
//the above is doing an if there is an equipment order already
$sql = "SELECT * FROM ssm_equipment";
if ($result = mysqli_query($conn, $sql)){
if(mysqli_num_rows($result)>0){
echo "<form method='post' action='actions/submit-equipment-order-action.php' id='equipmentOrderForm'>";
echo "<div class='input-group mt-3 mb-3'>";
echo "<div class='input-group-prepend'>";
echo "<span class='input-group-text'>Search (alt/option+s)</span>";
echo "</div>";
echo "<input id='equipmentTableSearch' onkeyup='searchEquipmentTable()' type='text' class='form-control' placeholder='Plates...Soup Spoon...Red Wine Glass...'>";
echo "<button type='submit' name='equipment_submit_button' class='btn btn-primary'>Submit</button'>";
echo "</div>";
echo "<table id='equipmentTable' class='mt-3 table table-striped table-hover table-bordered'>";
echo "<thead>";
echo "<tr class='text-center'><th>Equipment</th><th>Quantity</th></tr>";
echo "</thead>";
echo "<tbody>";
while ($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td style='width:70%;'>".$row['equipment_name']."</td>";
echo "<input type='hidden' name='equipmentId[]' value='".$row['equipment_id']."'>";
echo "<td class='text-center'><input name='equipmentQty[]' class='eqQty text-center up' type='text'></td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
echo "</form>";
}
}
}
}
?>
The following line is successfully showing the correct number of results, for how many items have a qty but i do not know how to use this information to populate the correct text boxes in the table.
while ($row2 = mysqli_fetch_array($result2)){ echo "XX "; }
HI Both,
Thanks for your info here - before seeing your replies, i wrote the following which seems to do what i want but as you said, it copies all of the content with it.
I will have a look at cleaning this up and will post the new version once finalized.
i=0;
function myF() {
console.log(i)
var chunk = document.getElementById('newMenuItemLine'+i);
var clone = chunk.cloneNode(true);
i++;
chunk.setAttribute("id", "newMenuItemLine" +i);
document.getElementById('wrapper').appendChild(clone);
}
Turns out that i have solved this one myself also, the issue was that i was passing a string in the array and not integers. When i changed the data type to 'is' rather than 'ii' the insert worked.
I am sorry all, as is always the case i have answered by own question shortly after posting.
function barCodeVal(e){
var code = e.keyCode;
console.log(e.keyCode);
}
thanks anyway, i am sure i will be back.
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.