2013-04-09 98 views
0

我想製作一個使用curl提交表單的php腳本。 我見過這方面的其他問題,並tryed像其他的答案,但我得到了相同的結果Php curl不提交表格

我有一個簡單的表格,呼應submited

<form action="form.php" method="GET"> 
<input type="text" name="name"/> 
<input type="submit"> 
</form> 

<?PHP 
if (! empty($_GET['name'])){ 
    echo 'Hello, ' . $_GET['name']; 
} 
?> 

,這裏的值是捲曲腳本

$ch = curl_init(); 

    curl_setopt($ch, CURLOPT_URL, "http://www.mydom.com/form.php"); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, array(
    'name' => 'Aname', 
    'submit' => 'submit' 
)); 
    curl_setopt($ch, CURLOPT_HEADER, false); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    $result = curl_exec($ch); 
    echo "$result"; 

回送的結果就是沒有「你好&提交的值」

+2

你的'捲曲'正在使用POST,但你的表單正在等待GET – andrewsi 2013-04-09 16:06:13

+0

除了每個人都指出的那個之外,一切似乎都很好。嘗試$ _POST而不是$ _GET – acpmasquerade 2013-04-09 16:18:30

回答

2

形式這是不是是因爲這一行

if (! empty($_GET['name'])){ 
    echo 'Hello, ' . $_GET['name']; 
} 

您正在向頁面發送POST請求,但您正在查找GET數據。

編輯 捱打答案>。 <