gpt4 book ai didi

php - 值未插入 WordPress 表中

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

我正在尝试在模板文件中插入我开发的自定义表单值。这样我就在 wordprress 数据库中创建了一个 customer_info 表。这是正确的做法吗?

这是我迄今为止尝试过的代码:

<?php
if(isset($_POST['submit']))
{
global $wpdb;
echo $q=$_GET['q'];
$a=$_POST['name'];
$b=$_POST['lname'];
$c=$_POST['email'];
$d=$_POST['mobile'];
$e=$_POST['phone'];
$f=$_POST['accom'];
$g=$_POST['adress'];
$h=$_POST['remark'];
$wpdb->insert( 'customer_info', array( 'post_id' => $q, 'name' => $a,'lname' => $b, 'email' => $c,'mobile' => $d, 'phone' => $e,'adress' => $g, 'remark' => $h ), array( '%d', '%d','%s', '%s' ,'%s', '%s' ,'%s', '%s' ) );
}

?>

为什么它不起作用?通过同一过程,我在本地主机上插入了两个表单值。

正如在核心 php 中一样,我知道如何调试等,所以请告诉我如何在 WordPress 中做到这一点,因为 WordPress 有自己的用于数据库操作的 wpdb 类。

这是我的 html 表单

<form method="post" action="">
<table width="50%" align="left">
<h3>Customer Info</h3>
<tr>
<td valign="top">Name</td><td valign="top"><input type="text" name="name" /></td>
</tr>
<tr>
<td valign="top">Last Name</td><td valign="top"><input type="text" name="lname" /></td>
</tr>
<tr>
<td valign="top">Email</td><td valign="top"><input type="text" name="email" /></td>
</tr>
<tr>
<td valign="top">mobile</td><td valign="top"><input type="text" name="mobile" /></td>
</tr>
<tr>
<td valign="top">Phone</td><td valign="top"><input type="text" name="phone" /></td>
</tr>


<tr>
<td valign="top">Address</td><td valign="top"><input type="text" name="adress" /></td>
</tr>

<tr>
<td valign="top">Remark</td><td valign="top"><input type="textarea" name="remark" /></textarea></td>
</tr>
<tr>
<td valign="top">Click for continue</td><td valign="top"><input type="submit" name="submit" value="Continue" /></td>
</tr>
</table>
</form>

如果我错过了什么,请随时询问。

非常感谢。

最佳答案

你可以尝试这样的错误

1) Enable database error display via $wpdb->show_errors()
2) Check what query is being formed and run via $wpdb->last_query

name您的情况下的字段是一个字符串,并且您已将其定义为插入数组中的整数,请使用 '%s'为此,而不是 %d 。也使用不同的name输入的属性,因为 name是保留字,可能是这个原因。

关于php - 值未插入 WordPress 表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19533213/

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