所以,我是cURL總noob,但由於我有一些問題使用PHP通過Flash as3插入數據到數據庫(文件在不同的服務器),我被建議使用cURL腳本來橋接它們兩者。cURL張貼空值(通過Flash as3)
因此,這裏是我的捲曲代碼(這是一份來自另一個問題粘貼,我只是改變了值,所以原諒我,如果這裏存在任何明顯的錯誤):
<?php
//where are we posting to?
$url = 'url'; //I have the correct url of the file (insert.php) on the other server
//what post fields?
$fields = array(
'Nome'=>$_POST['nome'],
'Email'=>$_POST['email'],
'Idade'=>$_POST['idade'],
'Profissao'=>$_POST['profissao'],
'Pais'=>$_POST['pais']
);
//build the urlencoded data
$postvars='';
$sep='';
foreach($fields as $key=>$value)
{
$postvars.= $sep.urlencode($key).'='.urlencode($value);
$sep='&';
}
//open 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($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
?>
,這裏是閃存AS3
function WriteDatabase():void{
var request:URLRequest = new URLRequest ("curl.php file here");
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.nome = ContactForm.nomefield.text;
variables.email = ContactForm.emailfield.text;
variables.idade = ContactForm.idadefield.text;
variables.profissao = ContactForm.proffield.text;
variables.pais = LanguageField.selectedbutton.text;
request.data = variables;
var loader:URLLoader = new URLLoader (request);
loader.addEventListener(Event.COMPLETE, onComplete);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(request);
function onComplete(event):void{
trace("Completed");
}
}
// I am assuming (incorrectly perhaps) that if is called the same way you would call a php file. It also traces "Completed" inside the flash, so it comunicates with it.
我知道這是正確調用其他的文件,因爲它實際上在數據庫中創建一個條目,但一切都是空白。每個領域。我也知道其他文件的作品,因爲當我離線測試閃存文件時,它的工作原理就是當它在線時不工作。
任何幫助是apreciated。
不要試圖一次解決問題的兩端!將變量設置爲您知道應該工作的某些默認值,然後在瀏覽器中調試PHP腳本。只有獲得預期結果後,才能開始使用Flash腳本。 – weltraumpirat
...然後使用只接收來自Flash的值但不調用數據庫的虛擬腳本。然後,最後,你可以把這兩件事整理在一起。 – weltraumpirat
你能告訴我們'insert.php'嗎? – mgraph