Add to Database Mysql from table in php

Discussion in 'PHP' started by eyucks, Jul 12, 2007.

  1. #1
    can you help me about how to adding in mysql database..
    pleasee...

    this my coding...:



    <script language="javascript">

    function addRow(aTable)
    {
    aRow = aTable.insertRow(aTable.rows.length);
    numCells=5
    var col_dir = ['<input type="text" name="No">',
    '<input type="text" name="Title">',
    '<input type="text" name="Quantity">',
    '<input type="text" name="Email">',
    '<input name="button2" type="button" id="button4" onClick="delRow(this)" value="delete">']

    aCell = aRow.insertCell(0);

    for (i=0;i<numCells;i++){
    aCell = aRow.insertCell(i);
    aCell.innerHTML= col_dir
    }

    aCell.innerHTML='<input name="button2" type="button" id="button4" onClick="delRow(this)" value="delete">'
    }

    function delRow(row)
    {
    row.parentNode.parentNode.parentNode.deleteRow(row.parentNode.parentNode.rowIndex);
    }

    </script>

    <body>
    <?php
    //to insert data into database whenever user clicks add button
    if(isset($_POST['add'])){
    $No=addslashes($_POST['No']);
    $Title=addslashes($_POST['Title']);
    $Quantity=addslashes($_POST['Quantity']);
    $Email=addslashes($_POST['Email']);

    include'db_connect.php';
    $query="INSERT INTO Goods(No,Title,Quantity,Email)VALUES('$No','$Title','$Quantity','$Email')";
    $result=mysql_query($query);
    if($result)
    echo 'Add success';
    else
    echo 'Add failed';
    }
    ?>

    <p>&nbsp;</p>
    <form name="myForm" method="GET">
    <table id="myTable" name="Table" border="0" width="649">
    <tbody id="myTableTBody" name="TableTBody">

    <tr>
    <td width="144">No.</td>
    <td width="144">Title</td>
    <td width="144">Quantity</td>
    <td width="144">Email</td>
    </tr>
    <tr>
    <td><input type="text" name="No." value=""></td>
    <td><input type="text" name="Title" value=""></td>
    <td><input type="text" name="Quantity" value=""></td>
    <td><input type="text" name="Email" value=""></td>
    </tr>
    </table>
    <p>
    <input name="add" type="button" id="button3" onClick="addRow(document.getElementById('myTable'))" value=" add row">
    </p>
    <p>
    <input type="submit" name="add" value="Submit">
    </p>
    </form>
    </body>
     
    eyucks, Jul 12, 2007 IP