【问题标题】:save some data in mysql on my server by curl通过 curl 在我的服务器上的 mysql 中保存一些数据
【发布时间】:2022-01-16 20:20:32
【问题描述】:

我想通过 curl 将一些数据保存在我服务器上的 mysql 中,我的代码是这样的
我的卷发

  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!";}     
 }  ?>

但数据不保存。请指导我哪里错了?

我想通过curl将一些数据保存在我服务器上的mysql中,我尝试了很多但没有成功

【问题讨论】:

  • 看起来保存到数据库是在verified_user.php 中完成的,所以我们需要查看该文件的作用。你得到什么错误?
  • 您发布的代码会产生解析错误
  • brombeer 我需要创建 Verified_user.php。问了你同样的问题

标签: php mysql php-curl


【解决方案1】:

什么意思?
你不能通过 cURL 保存数据,你可以通过 cURL 发送请求。 但我想您想通过 cURL 向您的服务器发送请求并将一些数据存储在 cURL 请求中。 所以你需要一个函数或代码或东西来从请求中获取一些数据并将数据存储在数据库中。

您可以通过 $_REQUEST 获取请求中的所有数据

例子

$user_id=$_REQUEST['user_id'];
$user_name=$_REQUEST['user_name'];

还有…… 然后你可以将这些数据存储在你的数据库中。

【讨论】:

  • 我的行为与 Verified_user.php <?php $con=mysqli_connect('localhost','root','','db_name'); $user_id=$_REQUEST['user_id']; $user_name=$_REQUEST['user_name']; mysqli_query($con,"insert into verification_user(user_id,user_name)values ('$user_id','$user_name'); exit; ?> 类似,但没有插入数据数据库。
  • 您的 verify_data_on_server 函数在哪里调用?你能把你的完整代码发给你吗?
  • ''
猜你喜欢
  • 1970-01-01
  • 2016-05-13
  • 2016-08-20
  • 1970-01-01
  • 1970-01-01
  • 2022-12-05
  • 1970-01-01
  • 1970-01-01
  • 2020-06-08
相关资源
最近更新 更多