我已经有一个 PHP/JS 页面,它适用于我试图在 Wordpress 中创建的内容(http://msf.willcannondev.me)。数据正在写入数据库,填写完字段后点击 CRM 按钮即可查看。
在 WP 中,我尝试了以下方法来插入数据,但没有任何成功。
在 PHP/JS 站点中,我使用以下内容并将数据插入数据库:
> $connect = new PDO("mysql:host=xxxxxx;dbname=xxxxxx", "xxxxxx", "xxxxx");
$message = '';
$ip = $_SERVER['REMOTE_ADDR'];
if(isset($_POST["submit"])) {
$query = "
INSERT INTO wpbestp_home_purchase
(salesprice, loan_amount, income, fName, lName, property_street, property_city, property_state, property_zipcode, primary_phone, email, ip, message) VALUES
(:salesprice, :loan_amount, :income, :fName, :lName, :property_street, :property_city, :property_state, :property_zipcode, :primary_phone, :email, :ip, :message)";
$refi_data = array(
':salesprice' => $_POST["salesprice"],
':loan_amount' => $_POST["loan_amount"],
':income' => $_POST["income"],
':fName' => $_POST["fName"],
':lName' => $_POST["lName"],
':property_street' => $_POST["property_street"],
':property_city' => $_POST["property_city"],
':property_state' => $_POST["property_state"],
':property_zipcode' => $_POST["property_zipcode"],
':primary_phone' => $_POST["primary_phone"],
':email' => $_POST["email"],
':ip' => $_SERVER['REMOTE_ADDR'],
':message' => $_POST["message"]
);
$statement = $connect->prepare($query);
if($statement->execute($refi_data)) {
$message = '
<div class="alert alert-success">
Thank you for getting in touch with us! We will try our best to respond back to you within 24 hours.
</div>
';
} else {
$message = '
<div class="alert alert-error">
There is an error adding the new record.
</div>';
}
}
?>
在 WP 中,我尝试了 PHP 脚本和以下脚本,但都没有插入数据。(我相信 wp-config.php 文件是 MySQL 连接所在的位置,所以我只需要该文件):
<?php
require_once( 'wp-config.php');
global $wpdb;
$message = '';
$ip = $_SERVER['REMOTE_ADDR'];
if(isset($_POST['submit'])) {
$wpdb->insert( 'wpbestp_home_purchase', array(
'salesprice' => $_POST['salesprice'],
'loan_amount' => $_POST['loan_amount'],
'income' => $_POST['income'],
'fName' => $_POST['fName'],
'lName' => $_POST['lName'],
'property_street' => $_POST['property_street'],
'property_city' => $_POST['property_city'],
'property_state' => $_POST['property_state'],
'property_zipcode' => $_POST['property_zipcode'],
'primary_phone' => $_POST['primary_phone'],
'email' => $_POST['email'],
'ip' => $_SERVER['REMOTE_ADDR'],
'message' => $_POST['message'],
array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )
);
$statement = $connect->prepare($query);
if($statement->execute($refi_data)) {
$message = '
<div class="alert alert-success">
Thank you for getting in touch with us! We will try our best to respond back to you within 24 hours.
</div>';
} else {
$message = '
<div class="alert alert-error">
There is an error adding the new record.
</div>';
}
}
?>
如果有人能够向我展示我做错了什么,我将不胜感激,因为我是 Wordpress 的新手。
提前致谢。