将数据插入已存在的表中

问题描述

我已经有一个 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' )
 );
 $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 的新手。

提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)