【问题标题】:Update a field in output php query from mysql in a table [closed]从表中的mysql更新输出php查询中的字段[关闭]
【发布时间】:2014-06-29 04:46:06
【问题描述】:

我已经在这附近呆了好几个小时了,但我不知道该去哪里。

我想从表中的 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>

我只是停在这里,因为它开始让我出错,我想知道是否有更好的方法来做到这一点..

【问题讨论】:

  • 我不确定你想要什么,但那可能是我。无论如何,我首先建议使用 PDO 连接到您的数据库,或者至少使用 MySQLi,它们都更安全!
  • 感谢您的建议,我会调查一下 :)

标签: php mysql html-table row edit


【解决方案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);
    }
}
?>

【讨论】:

  • 谢谢你!我感谢您的努力,我的代码现在好多了!干杯:)
猜你喜欢
  • 1970-01-01
  • 2019-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多