好吧我是新來的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代碼。
<?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 2009-10-17 18:58:19
我已經編輯了我的答案几次;希望這可以幫助 ! – 2009-10-17 19:04:59