从表中的mysql更新输出php查询中的字段

时间:2014-05-11 22:21:01

标签: php mysql html-table row edit

我现在已经在这几个小时了,而且我不知道该往哪里转。

我想从表中的mysql更新输出PHP查询中的字段。

我只需要一个小按钮或类似的东西来插入"是"到该记录中的一个字段。

这是我的代码:

<body>
<?php
$connection = mysql_connect('localhost', 'root', ''); //The Blank string is the password
mysql_select_db('test');

mysql_set_charset('utf8');

$query = "SELECT * FROM simulac";
$result = mysql_query($query);

echo "<table>"; // start a table tag in the HTML

while($row = mysql_fetch_array($result)){   //Creates a loop to loop through results
echo "<tr><td>" . $row['id'] . "</td><td>" . $row['name'] . "</td><td>" . $row['over'] . "</td><td><form action="" method="POST"><input type="submit" value="Concluido" name="submit" class="enviar" /></form></td></tr>";  }

echo "</table>"; //Close the table in HTML

mysql_close(); //Make sure to close out the database connection

?>

</body>

我刚停在这里,因为它开始让我犯错,我想知道是否有更好的方法来做这件事。

1 个答案:

答案 0 :(得分:-1)

按此顺序尝试一下(对我来说似乎更好)

<form>
<table>
<tr>

<td>...
</td>
<td>...
</td>
<td>
   <?php echo('<input type="submit" value="Concluido" name="submit.'['.$row['id'].']'. '" class="enviar" />'?>
</td>


</tr>
</table>

</form>

//Check button
<?php
if (isset($_POST['submit'])) {
    reset($_POST['submit']);
    foreach ($_POST['submit'] as $name => $value) {
        //do some update on ... $name);
    }
}
?>