0
我見過這個問題,但答案不是很清楚。 我的代碼是。致命錯誤:無法重新聲明類數據庫。怎麼修?
的index.php
<?php include 'header.php'; ?>
<?php
include "class.users.php";
if(isset($_POST['login'])) {
$username = $_POST['username1'];
$password = $_POST['password1'];
$users->login($username, $password);
}
?>
class.users.php
<?php
include "connect.php";
class Users extends Database {
public function login($username, $password) {
$stmt = $this->mysqli->prepare("SELECT username, password FROM users WHERE username = ? AND password = ? LIMIT 1");
$stmt->bind_param('ss', $username, $password);
$stmt->execute();
$stmt->bind_result($username, $password);
$stmt->store_result();
if($stmt->num_rows == 1) {
while($stmt->fetch()) {
$_SESSION['username'] == $username;
header("Location: dashboard.php");
}
} else {
return false;
}
$stmt->close();
$stmt->free_result();
}
}
$users = new users();
?>
connect.php
<?php
class Database {
public function __construct() {
$host = 'localhost';
$user = 'root';
$pass = '';
$name = 'meeboo3';
$this->mysqli = new mysqli($host, $user, $pass, $name);
}
}
?>
類數據庫不叫兩次嗎?那麼它是一個錯誤呢?任何人都可以解釋爲什麼在評論中。
'connect.php'中有什麼? – 2014-09-02 22:32:22
我不知道類數據庫是否已經聲明或包含在header.php或connect.php? – 2014-09-02 22:32:32
對不起,我忘了加入connect.php – logchipperman 2014-09-02 22:33:16