简体   繁体   中英

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. 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

2) add name to all input box with in 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:

in $_POST[custom] you will get array of values of all input field custom.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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