如何POST并将数组值插入mysql表

时间:2015-01-07 06:12:44

标签: php mysql

我有html表单,如何插入mysql表并且还需要发送电子邮件这个细节,我知道这太难了,任何人都可以提出一些想法以及如何开始。

<form id="validation" action="insert_export.php" method="post" class="form-horizontal" enctype="multipart/form-data">

<table class="table table-bordered" style="width:95%;float:right;">
              <tr>
                <th><input class='check_all' type='checkbox' onclick="select_all()"/></th>
                <th>S. No</th>
                <th>Item Code</th>
                <th>Product Name</th>
                <th>Quantity</th>

              </tr>
              <tr>
                <td><input type='checkbox' class='case'/></td>
                <td><span id='snum'>1.</span></td>
                <td><input type='text' id='itemcode_1' name='itemcode[]'/></td>
                <td><input type='text' id='productname_1' name='productname[]'/></td>
                <td><input type='text' id='quantity_1' name='quantity[]'/></td>

              </tr>  
            </table>
    </form>

1 个答案:

答案 0 :(得分:0)

    session_start();
    //In right side, variables contains Post data from form fields.
    //Posted data are stored in Variables
    $itemCode               =   $_POST['item_code'];
    $productName            =   $_POST['product_name'];
    $quantity               =   $_POST['quantity'];

    mysql_connect('localhost','root','') or die("Could not connect");
    mysql_select_db('your database name') or die('Database not found!');        

    //This query will insert data in your database.         
    $query  =   "INSERT INTO tablename(table_fieldname1, table_fieldname2,  table_fieldname3) VALUES('$itemCode', '$productName', '$quantity')";

    $result  =  mysql_query($query);

    if($result){
    header('location: yourpage.php');
    }else{
    echo "Not Entered successfully";
    }