在WordPress中用PHP和复选框更新MySQL表


Updating MySQL table with PHP and checkboxes in WordPress

在我的网站上输入链接描述这里我使用复选框按钮更新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 />";

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

你知道怎么处理这个问题吗?谢谢。

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

在WordPress中,建议使用WordPress内置查询。因此,它可以最大限度地与服务器兼容。

参考: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..