こんにちは、私は数年前にやったPHP 5で動作するようにこのコードをコーディングしました。PHP 7で動作させようとしています。私はこのエラーが発生し続けているが、それを修正する方法はわからないので、PHPサイトで言うとおりに変更しようとしましたが、PHPでコーディングしてから非常に長い時間がかかりました。ありがとう。PHP 7 - MySQLのエラーmysqli_query()のパラメータ
これは私のエラーです:
Warning: mysqli_query() expects at least 2 parameters, 1 given in send_url.php on line 20 Warning: mysqli_fetch_assoc() expects parameter 1 to be resource, null given in send_url.php on line 22 No more downloads
、これは私のコードです:
// Create connection
$connect = new mysqli($host, $username, $password, $database);
// Check connection
if ($connect->connect_error) {
die("Connection failed: " . $connect->connect_error);
}
echo "Connected successfully";
$q = $_GET[q];
if (!$q)
{
$q = "0";
}
$query = "SELECT * FROM links WHERE link = '$q'";
$result = mysqli_query($query);
$row=mysqli_fetch_assoc($result);
$filepath = $row["getfilename"];
$dltimes = $row["dltimes"];
$minusone = $dltimes-1;
if ($dltimes>0)
{
$location = 'myfiles/'. $filepath;
$changequery = "UPDATE links SET dltimes = '$minusone' WHERE link = '$q'";
$changeresult = mysqli_query($changequery);
$filename = 'dummy.zip';
$filename = realpath($location);
$file_extension = strtolower(substr(strrchr($filename,"."),1));
switch ($file_extension) {
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpe": case "jpeg":
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
if (!file_exists($filename)) {
die("NO FILE HERE");
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=\"".$filepath. "\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: "[email protected]($filename));
set_time_limit(0);
@readfile("$filename") or die("File not found.");
}
else
{
echo "No more downloads";
}
mysqli_queryは($接続、$クエリ)を必要 – clearshot66
は、関数は、少なくとも2つのパラメータを期待しています。ドキュメンテーションで定義されているように:https://secure.php.net/manual/en/mysqli.query.phpあなたは1つのパラメータしか提供していません。エラーが具体的にあなたに伝えているのと同じです。 – David