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

标签 php mysql wordpress checkbox

在我的网站上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/

相关文章:

php - 我如何整合 Reddit 页面/帖子排名算法?

mysql - 使用时间戳时 order by 子句如何工作?

PHP 应用程序在迁移到 Windows 机器后无法运行

wordpress - 如何使用没有插件的WordPress导航菜单创建面包屑?

php - Laravel 具有两种不同的用户类型

php - 如何在 PHP 中通过 Retrofit POST 请求发送服务器端提取请求正文

mysql - 具有多个分隔符的 AWK

mysql - Wordpress 不适用于 docker compose

javascript - 使用复选框中的 window.location.assign 添加多个 GET 参数到 URL

php - 将时间转换为秒