2016-08-29 98 views
1

在我的网站我使用复选框按钮在MySQL表(页与登录)更新数据enter link description here在PHP中使用此代码工作正常:更新MySQL表用PHP和复选框在WordPress

<?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!

+0

是否在您的服务器上启用了PHP短标签?你正在混合使用<?php和'<?'(就像你在复选框中输出的地方一样)。 –

回答

0

在WordPress中,建议使用WordPress内置查询。所以它也可以与服务器保持最大的兼容性。

参考:https://codex.wordpress.org/Class_Reference/wpdb

全球WPDB $;

而且所有的以下功能将附加被定义为全球数据库..

$wpdb->insert('wp_submitted_form', array(
    'name' => 'Kumkum', 
    'email' => '[email protected]', 
    'phone' => '3456734567', // ... and so on 
)); 

喜欢聪明人,你可以用它来更新/选择按你的意愿,它被认为是按照最好的之一到WordPress ..