gpt4 book ai didi

php - 使用 PHP 和 WordPress 中的复选框更新 MySQL 表

转载 作者:行者123 更新时间:2023-11-29 20:27:32 25 4
gpt4 key购买 nike

在我的网站上enter link description here我使用复选框按钮来更新 MySql 表中的数据(页面需要登录),并在 PHP 中使用此代码,工作正常:

<?php
$sql="SELECT *,cast(DATE_FORMAT(datum,'%d-%m-%Y ') AS CHAR(32)) as datum FROM wedstrijden";
$result=mysqli_query($db,$sql);

$count=mysqli_num_rows($result);

?>
<table style="width: 100%;">
<tr>
<td><form name="frmactive" action="1fanionchange.php" method="post">
<tr>
<td colspan="6"><input name="activate" type="submit" id="activate" value="Open selected" />

</tr>
<tr>
<td>&nbsp;</td>
</tr><tr>
<td align="center"><!--<input type="checkbox" name="allbox" title="Select or Deselct ALL" style="background-color:#ccc;"/> --></td>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Datum</strong></td>
<td align="center"><strong>Uur</strong></td>
<td align="center"><strong>Thuis</strong></td>
<td align="center"><strong>Uit</strong></td>
</tr>
<?php
while($rows=mysqli_fetch_array($result)){
?>
<tr>
<td align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
<td align="center"><? echo $rows['id']; ?></td>
<td align="center"><? echo $rows['datum']; ?></td>
<td align="center"><? echo $rows['uur']; ?></td>
<td align="center"><? echo zoeknaam($rows['thuisploeg']); ?></td>
<td align="center"><? echo zoeknaam($rows['uitploeg']); ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="6"><input name="activate" type="submit" id="activate" value="Open selected" />
</tr>
</form>
</td>
</tr>
</table>

但是当我在 WordPress 中使用相同的代码(我试图在 WordPress 中制作网站)时,它不起作用并且没有显示任何记录。当我尝试使用以下命令查找行数时:

echo $count. "<br />";

我得到了该表中正确的记录数。但记录没有显示?

知道如何处理这个问题吗?谢谢。

PS。我在 WordPress 中使用插件 phpexec!

最佳答案

In WordPress it is suggested to use the WordPress builtin Queries. So that it can have maximum compatibility with the server too it is hosted.

引用:https://codex.wordpress.org/Class_Reference/wpdb

全局$wpdb;

以下所有函数都会附加定义为全局的数据库..

$wpdb->insert('wp_submitted_form', array(
'name' => 'Kumkum',
'email' => 'kumkum@gmail.com',
'phone' => '3456734567', // ... and so on
));

同样,您可以根据您的意愿使用它进行更新/选择,根据 WordPress,它被认为是最好的。

关于php - 使用 PHP 和 WordPress 中的复选框更新 MySQL 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39211563/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com