Reputation: 11
I want to make a php script that submits a form using curl. I've seen the other questions regarding this, and tryed like on other answers but i get the same result
I have a simple form that echo the value 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'];
}
?>
and here is the curl script
$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";
The echoed result is just the form without the "hello & submitted value"
Upvotes: 0
Views: 151
Reputation: 587
Wouldn't this be because of this line
if (! empty($_GET['name'])){
echo 'Hello, ' . $_GET['name'];
}
you are sending a POST request to the page but you are looking for GET data.
EDIT Got beaten to the answer >.<
Upvotes: 2