나는 php와 mysql에 익숙하지 않다. 웹 페이지 히트 카운터를 만들려고했지만 내 페이지 카운터가 올바르게 업데이트되지 않았고 아래에 나열된 경고가 표시된다.PHP와 MySQL hitcounter 문제가 있습니까?
Warning: mysqli_query() expects at least 2 parameters, 1 given in
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in
다음은 아래 PHP 코드입니다.
mixed mysqli_query (mysqli $link , string $query [, int $resultmode ])
당신이 전달하는 의미 : 함수로 사용 mysqli_query의 매뉴얼에 따라 모든
$mysqli = new mysqli("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"INSERT INTO mysql_counter_logs (page) VALUES ('$page')");
mysqli_query($dbc);
첫째 :
<?php
$page = $_SERVER['SCRIPT_FILENAME'];
// Query member data from the database and ready it for display
$mysqli = new mysqli("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT id page FROM mysql_counter_logs WHERE page = '$page'");
if (mysqli_num_rows($dbc) == 0) {
$mysqli = new mysqli("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"INSERT INTO mysql_counter_logs (page) VALUES ('$page')");
mysqli_query($dbc);
} elseif (mysqli_num_rows($dbc) == 1) {
$mysqli = new mysqli("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"UPDATE mysql_counter_logs SET hits = hits + 1 WHERE page = '$page'");
mysqli_query($dbc);
}
//Retreives the current count
$count = mysqli_fetch_row(mysqli_query($mysqli,"SELECT hits FROM mysql_counter_logs"));
if (!$dbc) {
// There was an error...do something about it here...
print mysqli_error();
}
//Displays the count on your site
print "$count[0]";
?>
줄 12 및 18 – new
나는 내 대답을 두 번 편집했습니다. 이 도움이되기를 바랍니다! –