Home > front end >  Data not inserting in the database using a modal
Data not inserting in the database using a modal

Time:01-13

I am trying to update the status of my order using a modal. it doesnt shows any error but it does not update the status of the order in the database I already look at the form and my file is right. but i dont know why it does not update the status in my database. here is the image where i update the order status it exec

`<!-- Transaction History -->

          <button type="button"  data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span></button>
          <h4 ><b>Transaction Full Details</b></h4>
        </div>
        <div >
          <p>
            Date: <span id="date"></span>
            <span >Transaction#: <span id="transid"></span></span> 
          </p>
          <table >
            <thead>
              
              <th>Product</th>
              <th>Price</th>
              <th>Quantity</th>
              <th>Subtotal</th>
              <th>Status</th>
               

            </thead>
            <tbody id="detail">
              <tr>
                
                <td colspan="4" align="right"><b>Total</b></td>
                <td><span id="total"></span></td>
              </tr>

              <form action="order_edit.php" method="POST" enctype="multipart/form-data">

                <td colspan="3" align="right"><b>Status</b></td>
                <td><span id="total">
                  <select name="status" id="status"  required>
              <option value="1" <?php echo isset($meta['status']) && $meta['status'] == 1 ? 'selected' : '' ?>>Pending</option>
              <option value="3" <?php echo isset($meta['status']) && $meta['status'] == 3 ? 'selected' : '' ?>>Out for Delivery</option>
              <option value="4" <?php echo isset($meta['status']) && $meta['status'] == 4 ? 'selected' : '' ?>>Done and Paid</option>
                </select>
                </span></td>
                <td>

                  <button type="submit"  name="edit"><i ></i> Update</button>
                </td>
              </form>
            </tbody>
          </table>

          
        </div>
        <div >
          <button type="button"  data-dismiss="modal"><i ></i> Close</button>

        </div>
    </div>
</div>

`

`<?php include 'includes/session.php';

if(isset($_POST['edit'])){
    $id = $_POST['id'];
    $status = $_POST['status'];
    date_default_timezone_set("Asia/Manila");
    $date = date('Y-m-d h:i:sa');
    $date1 = date('Y-m-d h:i:sa');

    
    try{
    $stmt = $conn->prepare("SELECT * FROM sales WHERE id=:id");
    $stmt->execute(['id'=>$id]);
    $row = $stmt->fetch();

    
        $stmt = $conn->prepare("UPDATE sales SET dateDelivered=:dateDelivered, order_received=:order_received, status=:status WHERE id=:id");
        $stmt->execute(['dateDelivered'=>$date,'order_received'=>$date1,'status'=>$status, 'id'=>$id]);
        $_SESSION['success'] = 'Status updated successfully';
    
    

    
    
}
catch(PDOException $e){
        $_SESSION['error'] = $e->getMessage();
    }
    $pdo->close();
}
else{
    $_SESSION['error'] = 'Fill up Update Status form first';
}

header('location: sales.php');

?>`

CodePudding user response:

Add the hidden input tag in form tag

<input type="hidden" name="id" value="<?php echo $meta['id']; ?>">
  •  Tags:  
  • php
  • Related