【问题标题】:Insert data in mysql from contact form 7 using wordpress使用 wordpress 从联系表 7 将数据插入 mysql
【发布时间】:2016-12-23 03:36:38
【问题描述】:

我,尝试使用 wordpress 将我的联系表 7 中的数据插入 mysql。

为此,我创建了一个基本的联系表格:

<p>Your Name (required)<br />
[text* name:sName ] </p>

<p>Your Email (required)<br />
[email* name:sEmail] </p>

<input type="submit" name:submit>

这是php函数:

<?php 
require_once('../../../wp-load.php');
include ('../../../wp-config.php');
global $wpdb;    
if(isset($_POST['submit']))
{
$name=addslashes($_POST['sName']);
$email=addslashes($_POST['sEmail']);
$wpdb->insert("Users",array(
"sName"=>$name,
"sEmail"=>$email,
));
}    
$wpdb->show_errors();
?>

还有页面:

<form action="/wp-content/plugins/my-codes/insertUser.php" method="post">
[contact-form-7 id="11" title="Contact form 1"]
</form>

到目前为止,我知道 php 函数可以工作,并且我已经连接到数据库,因为如果我不使用联系表 7,而是在页面中使用以下代码(见下文),它会完美地插入信息

<form action="/wp-content/plugins/my-codes/insertUser.php" method="post">
Name: <input type="text" name="sName" />
Email: <input type="text" name="sEmail" />
<input type="submit" name="submit">
</form>

所以我知道问题出在联系表单的某个地方,但我看不出我做错了什么。有什么想法吗?

谢谢!

【问题讨论】:

  • 您正在使用正确的数据库接口。不要使用addslashes,它会破坏您的数据。
  • 我使用的是 latin1_swedish_ci,可以吗?
  • 您确实应该使用 UTF-8,但这不是重点。 addslashes 在数据中插入斜线,因此像 "O'Reilly" 这样的名称变成 "O\\'Reilly"。这是一个坏习惯。
  • 好的,但我没有使用 addslashes 我正在使用另一个。而且我认为问题来自联系表单代码,因为如果我使用不同的行为我没有问题。
  • 您的代码中显然包含addslashes。如果您不使用该代码,为什么它会出现在问题中?你也没有很好地解释你的问题。

标签: php mysql wordpress contact-form-7


【解决方案1】:

这是正确的做法:

<p>Your Name (required)<br /> </p>
[text* sName id:sName]

<p>Your Email (required)<br /></p>
[email* sEmail id:sEmail] 

<input type="submit" name="submit">

【讨论】:

    猜你喜欢
    • 2020-12-20
    • 2017-01-12
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    • 2012-06-25
    • 2020-05-30
    相关资源
    最近更新 更多