Jump to content

How to insert same item name with more quantity into the existing item row?


Ronel

Recommended Posts

// This is my actionpage.php
<?php
//session_start();
//Checking User Logged or Not
//if(empty($_SESSION['HR'])){
 //header('location:login.php');
//}

    

$host="127.0.0.1";
$username="root";
$pass="";
$db="loginsystem";

$conn=mysqli_connect($host,$username,$pass,$db);
if(!$conn){
	die("Database connection error");
}



if (isset($_POST["ronel"]))
    {
        $ponum = $_POST["ponum"];
        $podate = $_POST["podate"];
        $remarks = $_POST["remarks"];
        $status =  'stockin';
        $sql = "INSERT INTO purchaseorder(ponum, podate, remarks, status) VALUES ('$ponum','$podate','$remarks', '$status')";
        mysqli_query($conn, $sql);
        $purchaseid = mysqli_insert_id($conn);
 
        for ($a = 0; $a < count($_POST["itemname"]); $a++)
        {
            $sql = "INSERT INTO stock (purchaseid, itemname, poqty,unitno,entrydate,stockqty,deliver) VALUES ('$purchaseid', '" . $_POST["itemname"][$a] . "', '" . $_POST["poqty"][$a] . "','" . $_POST["unitno"][$a] . "','" . $_POST["entrydate"][$a] . "','" . $_POST["stockqty"][$a] . "','" . $_POST["deliver"][$a] . "')";
            mysqli_query($conn, $sql);
        }
 
        //echo "<p>Details has been added.</p>";
    	if(isset($_POST['ronel'])){
            header("location: insert.php");
        }
	
    }
 
?>

2. this is my form

               <form action="actionpage.php" method="post" name="ronel">    
                        <div class="col-25"><label>1. P.O Number:*</label>
                        <input type="number" style="position:absolute; left:14.2%;" name="ponum" placeholder="P.O Number.."></div>
                        <br><div class="col-25"><label>2. P.O Date:*</label>     
                        <input style="position:absolute; left:14.2%;" type="date" name="podate"></div>
                        <br>
                        <div class="col-25"><label>3. Remarks:*</label>
                        <input type="text" style="position:relative; left:3%;" name="remarks" placeholder="Remarks.."></div>       
                        <input type="hidden"  name="status">
<hr>
    <h5>4. Add rows to insert items</h5>
  <br/><table>
        <tr>
            <th>Sl</th>
            <th>Item Name</th>
            <th>P.O Quantity</th>
            <th>Unit No</th>
            <th>Entry date</th>
            <th>Stock Quantity</th>
            <th>Delivery Date</th>
            <th>Delete</th>
        </tr>
        <tbody id="tbody"></tbody>
    </table><br>    
    <button type="button" onclick="addItem();">Add Row</button>
    <input type="submit" name="ronel" value="Submit">
    </form>                 
<script>
    var items = 0;
    function addItem() {
        items++;
 
        var html = "<tr>";
            html += "<td>" + items + "</td>";
        
            html += "<td><select name='itemname[]'> <option value='Pen'>Pen</option><option value='Paper Ream'>Paper Ream</option><option value='Bottle'>Bottle</option><option value='Calendar'>Calendar</option><option value='File'>File</option></select></td>";
            //html += "<td><input type='text'  style='width:120px;' name='itemname[]'></td>";
            html += "<td><input type='number' style='width:90px;' name='poqty[]'></td>";
            html += "<td><input type='number' style='width:90px;' name='unitno[]'></td>";
            html += "<td><input type='date' style='width:125px;' name='entrydate[]'></td>";
            html += "<td><input type='number' style='width:90px;' name='stockqty[]'></td>";
            html += "<td><input type='date' style='width:125px;' name='deliver[]'></td>";
            html += "<td><button type='button' onclick='deleteRow(this);'>Del Row</button></td>"
        html += "</tr>";
 
        var row = document.getElementById("tbody").insertRow();
        row.innerHTML = html;
    }
 
function deleteRow(button) {
    button.parentElement.parentElement.remove();
    // first parentElement will be td and second will be tr.
}
</script>

kindly help needed

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.