I want to save some data in mysql on my server by curl, my code is something like this
my curl
function verify_data_on_server
($user_id,$user_name,$user_code,$user_type,$user_url,$ user_email)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://myurl.com/apis/verified_user.php");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query(array('user_id' => $user_id,'user_name' => $user_name,'user_code' => $user_code,'user_type' => $user_type,'user_url' => $user_url,'user_email' => $user_email)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close ($ch);
if ($server_output == "status") { echo "done"; } else { echo "fail!";}
} ?>
but data not save . please guide me where im wrong ?
I want to save some data in mysql on my server by curl, I tried a lot but didn't get any success
CodePudding user response:
what do you mean?
you can't save data by cURl, you can send requests by cURL.
but I suppose that you want to send a request to your server by cURL and store some data within cURL request.
so you need a function or code or stuff for getting some data from requests and storing data in the database.
you can get all data within requests by $_REQUEST
example
$user_id=$_REQUEST['user_id'];
$user_name=$_REQUEST['user_name'];
and stuff ... then you can store these data in your database.
CodePudding user response:
If you want to store data in a MySQL database, you should probably use something intended to do it. I don't think you can send data with curl, if I remember correctly it's only in one way.
Have you tried looking at that question?
If you need to store data, just use PDO.