PHP-使用cURL将数据发送到Salesforce,但不发布到数据库中 [英] PHP - Sending data to Salesforce with cURL but not posting in database

查看:38
本文介绍了PHP-使用cURL将数据发送到Salesforce,但不发布到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我正在使用wordpress中的salesforce,未使用wordpress-lead插件,我在模板中有一个表单,并且该表单通过cURL将数据发送到salesforce,并且还在其中发布数据数据库的原因是我必须生成一个密码,然后将其发送给用户,但它不能正常工作,正在使用salesforce,但无法在数据库中保存数据,这是我的代码,用于将数据发布到数据库中并生成密码

my problem is that i'm working with salesforce in wordpress, i'm not using wordpress-to-lead plugin, I have a form in a template and that form sends data to salesforce via cURL and also is posting data in database cause I have to generate a password and then send it to the user but its not working, is working salesforce but not saving data in the database, here is my code to post data in database and generate the password

$keysString = implode(", ", array_keys($blank_section));
          unset($_POST['userId']);
            $user_id = mysql_query("SELECT MAX(id) AS id FROM int_form_data");
                $user_id = $user_id+11;
            $passwordSend = 'INTELIGOS'.rand(10000, 5000000);
            $array_user_id = array('user_id' => $user_id, 'password' => $passwordSend);
            $posted_data = array_merge($_POST,$array_user_id);
    foreach($posted_data as $k=>$v) {
        $itfdatainfo[$k] = $v;
    }



    $itfkeys    = array_keys($itfdatainfo);
    $itfvalues = array_values($itfdatainfo);

    if(isset($_POST['submit'])) {

     $sql = "INSERT INTO int_form_data (".implode(',',$itfkeys).") VALUES('".implode("','",$itfvalues)."')";        

        $result = mysql_query($sql);
    }

在这里,我使用cURL将数据发送到Salesforce:

And here I use cURL to send data to Salesforce:

//Initialize the $query_string variable for later use
$query_string = "";
$kv = array();
//If there are POST variables
if ($_POST) {

//Initialize the $kv array for later use


//For each POST variable as $name_of_input_field => $value_of_input_field
foreach ($_POST as $llav => $value) {

//Set array element for each POST variable (ie. first_name=Arsham)
$kv[] = stripslashes($llav)."=".stripslashes($value);

}

//Create a query string with join function separted by &
$query_string = join("&", $kv);
}
//Check to see if cURL is installed ...
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}

//The original form action URL from Step 2 
$url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';

//Open cURL connection
$ch = curl_init();

//Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($kv));
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);

//Set some settings that make it all work 
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

//Execute SalesForce web to lead PHP cURL
$result = curl_exec($ch);

//close cURL connection
curl_close($ch);

任何人都知道为什么会这样吗?我将所有代码都放在wordpress的一个模板中

Anyone knows why is happening that? I have all the code in one template in wordpress

推荐答案

我正在查看此INSERT INTO int_form_data(".implode(',',$ itfkeys)."),并考虑$ itfkeys中是否有某些列名称需要放在反引号中,则将导致sql错误.

I'm looking at this INSERT INTO int_form_data (".implode(',',$itfkeys).") and thinking if some column name in $itfkeys needs to be enclosed in backticks then it would cause an sql error.

这篇关于PHP-使用cURL将数据发送到Salesforce,但不发布到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆