如何在PHP中创建curl文件以从URL获取数据?

时间:2019-04-08 06:43:03

标签: php

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$myDBname = 'jsv';
$conn = mysql_connect("localhost", "root");
mysql_select_db('jsv');
if(isset($_POST['update']))
{
$nam = $_POST['namnid'];
$mandag = $_POST['mandagid'];
$tisdag = $_POST['tisdagid'];
$torsdag = $_POST['torsdagid'];
$fredag = $_POST['fredagid'];

$sql = mysql_query("INSERT INTO jsv(CA_ID,Name,Address,Amount)  VALUES ('$mandag', '$tisdag', '$torsdag', '$fredag') WHERE Setup_Box_No = '$nam'", $conn);
if(!$sql )
{
  die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";

}

mysql_close($conn);
?>

1 个答案:

答案 0 :(得分:0)

您可以执行以下操作。您必须设置一个URL才能获取内容。 希望我能理解您的问题

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "http://www.example.com",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}