0
雖然我上登錄按鈕然後致命錯誤單擊:在C:\wamp\www\json\login.php
雖然我上登錄按鈕點擊然後致命錯誤發生呼叫成員函數執行()
Call to a member function execute() on a non-object
該誤差發生線路24。
我做了更改,但不起作用。方法無法正常工作。
login.php
文件
<?php
require("config.inc.php");
if (!empty($_POST)) {
$query = "SELECT id,username,password FROM users WHERE username = :username";
$query_params = array(
':username' => $_POST['username']
);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
$response["success"] = 0;
$response["message"] = "Database Error1. Please Try Again!";
die(json_encode($response));
}
$validated_info = false;
$row = $stmt->fetch();
if ($row) {
if ($_POST['password'] === $row['password']) {
$login_ok = true;
}
}
if ($login_ok) {
$response["success"] = 1;
$response["message"] = "Login successful!";
die(json_encode($response));
} else {
$response["success"] = 0;
$response["message"] = "Invalid Credentials!";
die(json_encode($response));
}
} else {
?>
<h1>Login</h1>
<form action="login.php" method="post">
Username:<br />
<input type="text" name="username" placeholder="username" />
<br /><br />
Password:<br />
<input type="password" name="password" placeholder="password" value="" />
<br /><br />
<input type="submit" value="Login" />
</form>
<a href="register.php">Register</a>
<?php
}
?>
config.inc.php
文件
<?php
$db = mysqli_connect('localhost','root','','json') or die(mysqli_error($connection));
?>
database
: -
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
--
-- Dumping data for table `users`
--
INSERT INTO `users` (`id`, `username`, `password`) VALUES
(1, 'admin', 'admin');
no sir此功能也會出錯 – Bhavesh
您是否嘗試實施您需要使用的示例鏈接? – Evgeniy
實際上我想登錄但執行()函數不起作用 – Bhavesh