【问题标题】:value not inserting in wordpress table值未插入 wordpress 表中
【发布时间】:2013-10-23 05:07:01
【问题描述】:

我正在尝试在模板文件中插入我开发的自定义表单值。这样我就在 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'  ) );
}

?>

为什么它不起作用?而通过相同的过程,我在 localhost 上插入了两个表单值。

在核心 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>

如果有什么我遗漏的,请随时询问。

非常感谢。

【问题讨论】:

  • 尝试echo $wpdb-&gt;last_query打印查询。
  • 好的............
  • 有什么问题?现在可以定义了吗?
  • 我不知道,当我点击提交按钮时,它重定向到错误 404,当我没有任何表单操作时找不到页面。我在wordpress方面不够好。所以你有什么想法......
  • 使用'%s' 作为数组中的名称字段。

标签: php mysql wordpress


【解决方案1】:

你可以试试这样的错误

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 是保留字,可能是这个原因。

【讨论】:

  • 是的,名称属性有问题,因为我更改了它,所以我的查询工作正常......感谢您的支持和时间...... :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-04
  • 1970-01-01
  • 2013-01-18
  • 2016-05-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多