简体   繁体   English

如何将数据从html网格推送到mysql?

[英]how to push data from html grid to mysql?

I am trying to push the data from this simple html grid into sql but I can't do it. 我正在尝试将数据从这个简单的html网格推送到sql中,但是我做不到。 in the beginning, I got the error that there was no index for the var impressions. 一开始,我得到一个错误,即没有var印象索引。 I fixed that. 我修好了 when I use just the advertiser value I can push the data into mysql while with the second value, I can't succeed. 当我仅使用广告客户值时,我可以将数据推送到mysql中,而使用第二个值时,我将无法成功。 can you explain me what I am doing wrong? 你能解释我做错了什么吗? Thanks in advance 提前致谢

<?php

    include_once 'con_ui.php';
    if(isset($_POST['btn-save']))
        {

     $advertiser = $_POST["advertiser"];
     $impressions = (isset($POST["impressions"])?
     $_POST["impressions"]:'');



            $sql_query = "INSERT INTO data(adv, imp) VALUES('$advertiser', '$impressions')";
     mysql_query($sql_query);

            // sql query for inserting data into database

    }
    ?>


     <html>
     <head>
     </head>
     <body>
     <form method="post">
     <table id="myTable" align='center' cellspacing=0 cellpadding=5 border=1> 

     <tr>
     <th>advertiser</th>
     <th>impressions</th>
     </tr>
     <td>

     <select name="advertiser" id="advertiser">
                <option value="">Select advertiser</option>
                <option value = "Brita ">Brita</option>
                <option value = "Sammontana">Sammontana</option>
        </select>

     </td>

    <td name= "impressions" id="impressions" >1000000</td>

     <td>
        <button type="submit" name="btn-save"><strong>SAVE</strong></button>
     </td>
    </form>
    </body>
    </html>

There's a few things wrong here: 这里有些错误:

Firstly the $POST in 首先是$ POST

   $impressions = (isset($POST["impressions"])?$_POST["impressions"]:'');

Is missing an underscore and should be a $_POST 缺少下划线,应为$ _POST

   $impressions = (isset($_POST["impressions"])?$_POST["impressions"]:'');

Secondly the browser won't recognize 其次,浏览器无法识别

<td name= "impressions" id="impressions" >1000000</td>

as a form field. 作为表单字段。 If you want to pass on values that the user can't edit you have a few options. 如果要传递用户无法编辑的值,则有一些选择。 You can use a hidden field like: 您可以使用以下隐藏字段:

<td><input type="hidden" name="impressions" id="impressions" value="1000000">1000000</td>

or you can use a text input and disable user input like 或者您可以使用文本输入并禁用用户输入,例如

<td><input type="text" name="impressions" id="impressions" value="1000000" disabled></td>

here you have the details of the code that i am using to achieve for adding the raws automatically, have the users entering data and keeping the code editable 在这里,您可以获得我用来自动添加原始代码,让用户输入数据并使代码可编辑的代码的详细信息

Hey thanks for your reply. 嘿,谢谢您的回复。 Problem being is i need to have the user enter the date into the cell and and have and the content should be editable. 问题是我需要让用户在单元格中输入日期,并且具有且内容应可编辑。 in addition i'm having a button add row, to insert a new raw but doesn't work if use the form type as input. 另外我有一个按钮添加行,以插入一个新的原始文件,但是如果使用表单类型作为输入则不起作用。 here you have the full code 这里你有完整的代码

    <?php
include_once 'con_ui.php';
if(isset($_POST['btn-save']))
{
 // variables for input data
 $advertiser = $_POST["advertiser"];
 $impressions = (isset($_POST["impressions"])?
    $_POST["impressions"]:'');

 // variables for input data

 // sql query for inserting data into database

        $sql_query = "INSERT INTO data(adv, imp) VALUES('$advertiser', '$impressions')";
 mysql_query($sql_query);

        // sql query for inserting data into database

}
?>


 <html>
 <head>
 <script>
 function myFunction() {
    var table = document.getElementById("myTable");
    var new_client = document.getElementById("advertiser_row1").innerHTML;
    var new_impressions = document.getElementById("impressions_row1").innerHTML;

    var row = table.insertRow(1);
    var cell1 = row.insertCell(0);
    var cell2 = row.insertCell(1);
}
    </script>
 </head>
 <body>

 <table id="myTable" align='center' cellspacing=0 cellpadding=5 border=1> 
 <form method="post">
 <tr>
 <th>advertiser</th>
 <th>impressions</th>
 </tr>
 <td>

 <select name="advertiser" id="advertiser_row1">
            <option value="">Select advertiser</option>
            <option value = "Brita ">Brita</option>
            <option value = "Sammontana">Sammontana</option>
    </select>

 </td>

<td><input type="text" name="impressions" id="impressions_row1" value="1000000"></td>


 <td>
<button onclick="myFunction()">Add Row</button>
</td>
<td>
 <button type="submit" name="btn-save">Save</button>
 </td>
</tr>
</form>
</table>

</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM