Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,
please help me i am using following code to insert data using dynamic text boxes.

i want to know how i delete and update record in dynamic texbox without refresh page.


row.html
HTML
<form class="product-item">

<table>
        <tr>
            <td>    <input type="checkbox" name="<?php echo($_POST['rowid'])?>" /> </td>
            <td><input type="text" name="<?php echo("desc".$_POST['rowid'])?>"></td>
            <td><input type="text" name="<?php echo("qty".$_POST['rowid'])?>"></td>
            <td><input type="text" name="<?php echo("unit".$_POST['rowid'])?>"></td>
            <td><input type="text" name="<?php echo("amount".$_POST['rowid'])?>"></td>

        </tr>

</table>
</form>


data.php
PHP
<?php


$con=mysql_connect("localhost","root","");
mysql_select_db("esol",$con);

$counter=count($_POST)/4;

for ($i=1; $i <=$counter; $i++)
{
    $val=$_POST['desc'.$i];
    $val2=$_POST['qty'.$i];
    $val3=$_POST['unit'.$i];
    $val4=$_POST['amount'.$i];
    mysql_query("insert into invoice (description,quantity,unit,total) values('$val','$val2','$val3','$val4')",$con);
}

?>


index.php
HTML
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<input type="button" value="addrow" onclick="addrow()">
<input type="button" value="deleterow" onclick="deleteRow()">


<div id="output">


</div>
<script type="text/javascript" src="../jquery.js"></script>
<input type="button" value="insert" onclick="sub();">
<div id="msg"></div>

<script type="text/javascript">
    var i=0;


    function addrow()
    {

        i++;
        $.post("row.php",{rowid:i},function(data)
        {

            $("#output").append(data).show();
        });
    }

    function sub()
    {
        $.post("data.php",$("form").serialize(),function(data)
        {
            $("#msg").html(data).show();
        });
    }
</script>
Posted
Comments
Palash Mondal_ 1-Oct-15 0:22am    
Please add addrow() & deleteRow() js code also.
Hani Mehdi 1-Oct-15 3:31am    
what function i put in deleteRow() ??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900