简体   繁体   English

获取表中输入的值,然后保存在mySql数据库中

[英]Get value of input in table and then save in mySql database

I have seen some answers but I have not found anything that I want. 我看到了一些答案,但没有找到我想要的任何东西。 I have a table with these rows: 我有一个带有这些行的表:

while ($rown = mysql_fetch_assoc($resulti)){
    echo "<tr style=text-align:center>";
    echo "<td>".$rown['emri']."</td>";
    echo "<td>".$rown['mbiemri']."</td>";
    echo "<td>".$rown['dega']."</td>";
    echo "<td>".$rown['id']."</td>";
    echo "<td>".$rown['viti_shkollor']."</td>";
    echo "<td><input type=text style= width:30px />"</td>";
    echo "</tr>";
} 

It works perfectly but I want to get the values of input type that user enters and then to put them in a mySql database. 它工作正常,但我想获取用户输入的输入类型的值,然后将其放入mySql数据库中。 Also the table has a submit button as below so when the user completes all of the table inputs then press the submit and all of values go to the database. 该表还具有一个提交按钮,如下所示,因此当用户完成所有表输入后,请按提交,所有值都将进入数据库。

 <input type="submit" value="prano" name="prano" style="margin:0 auto;" />

It is difficult for me to get the value of input and to put it in a variable. 对我来说,很难获得输入的值并将其放入变量中。 I hope you understand my question. 我希望你能理解我的问题。 Please help me. 请帮我。

there are few points which you need to include: 您需要包括以下几点:

1) add form in to your html 1)将表单添加到您的html中

2) add name to all input box with in while 2)使用while将名称添加到所有输入框

echo '<form action="test.php" method="post">';

while ($rown = mysql_fetch_assoc($resulti)){
    echo "<tr style=text-align:center>";
    echo "<td>".$rown['emri']."</td>";
    echo "<td>".$rown['mbiemri']."</td>";
    echo "<td>".$rown['dega']."</td>";
    echo "<td>".$rown['id']."</td>";
    echo "<td>".$rown['viti_shkollor']."</td>";
    echo "<td><input name='custom[".$rown['id']."]' type=text style= width:30px />"</td>";
    echo "</tr>";
} 

echo "</form>";

So that now in test.php: 所以现在在test.php中:

in $_POST[custom] you will get array of values of all input field custom. $_POST[custom]您将获得所有输入字段custom的值数组。

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

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