0

Fatal error: Call to undefined function curl_init() in C:\xampp\htdocs\lol.php on line 9

Basically this isn't working, I have no idea what's wrong with it all of the fields in the POST request are correct (As a HTML post form with a action to the URL works perfectly).

Script:

<?php
$url = 'myurl';
$postData = array();
$postData['name'] = 'jay'
$postData['age'] = '0';
$postData['gender'] ='female';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$result = curl_exec($ch);
curl_close($ch);
?>
brasofilo
  • 25,496
  • 15
  • 91
  • 179
user3000453
  • 31
  • 1
  • 4
  • Add `echo curl_error($ch);` after `$result = curl_exec($ch);` -- does it output anything? – Amal Murali Nov 22 '13 at 16:46
  • Nothing happens, even if i put a echo after it. It doesn't do what I want, since nothing pops up in my database (should appear in my database don't worry about that part though) – user3000453 Nov 22 '13 at 16:47
  • the first thing would be to identify if the request is sent. If yes, is this received ? If yes, the the erro is most probably in the script at 'myurl'... And yes we should worry on that part as you don't provide any info on what isn't working exactly – Laurent S. Nov 22 '13 at 16:47

1 Answers1

1

Your code is showing syntax error, in $postData['name'] = 'jay'

 $postData = array();
 $postData['name'] = 'jay';
 $postData['age'] = '0';
 $postData['gender'] ='female';

To make sure you have enabled curl or not. just place this inyour php file and find curl extension enabled in your instance.

 <?php phpinfo();?>

Enable curl in windows xampp: How to enable curl in xampp?

Community
  • 1
  • 1
Krish R
  • 22,583
  • 7
  • 50
  • 59