0

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"

2
  • 2
    Your curl is using POST, but your form is expecting GET Commented Apr 9, 2013 at 16:06
  • Everything seems to be fine, except the one that everyone has pointed. Try $_POST instead of $_GET Commented Apr 9, 2013 at 16:18

1 Answer 1

2

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 >.<

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.