Jump to content

Adamhumbug

Members
  • Posts

    349
  • Joined

  • Last visited

Community Answers

  1. Adamhumbug's post in Submit large form created with select statement was marked as the answer   
    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 "; }  
  2. Adamhumbug's post in Simple Clone Row was marked as the answer   
    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); }  
  3. Adamhumbug's post in Load more content button JS and PHP was marked as the answer   
    i went this route in the end and didnt bother with data attributes.
    function getMoreNews(limit, offset){ $.ajax({ type: 'post', data: {"ajax" : 'one', "offset" : offset, "limit" : limit}, success: function(resp){ offset = offset + 1 limit = limit + 1 $('.moreNews').append(resp + "<div class='btn btn-secondary w-100 text-center loadMoreNewsTrigger mb-3' onclick='getMoreNews(1,"+offset+");' data-limit='1' data-offset="+offset+">-- Load More News --</div>") } }) };  
  4. Adamhumbug's post in Inserting Array into MySQL was marked as the answer   
    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.
  5. Adamhumbug's post in AJAX Success returning whole page html was marked as the answer   
    Turned out to be a miss-capitalised bit of data
    createNewgame should have been createNewGame
    Sorry all.
     
    Thanks for looking anyway.
  6. Adamhumbug's post in Html function call on keyup - get keycode from input was marked as the answer   
    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.
     
×
×
  • Create New...

Important Information

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.