更新...
我正在编写准备好的语句,并且收到以下错误消息:
注意:未定义索引:第 34 行 C:\Program Files (x86)\EasyPHP-12.1\www\inlogg_och_lagar\core.inc.php 中的用户名
致命错误:未捕获异常 'PDOException' 并带有消息 'SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在 C:\Program Files (x86)\EasyPHP-12.1\www\inlogg_och_lagar\core.inc.php:34 中的第 1 行的 ''' 附近使用正确的语法跟踪:#0 C:\Program Files (x86)\EasyPHP-12.1\www\inlogg_och_lagar\core.inc.php(34): PDOStatement->execute(Array) #1 C:\Program Files (x86)\EasyPHP- 12.1\www\inlogg_och_lagar\index.php(23): getuserrow('username') #2 {main} 抛出 C:\Program Files (x86)\EasyPHP-12.1\www\inlogg_och_lagar\core.inc.php 上线34
有人可以告诉我我做错了什么吗?这是一个简单的登录脚本。
这是 loginform.inc.php
<?php
if (isset($_POST['username'])&&isset($_POST['password'])) {
$username = $_POST['username'] ;
$password = $_POST['password'] ;
$password_hash = md5 ($password);
if ($username && $password)
{
$query ="SELECT * FROM USERDATA where `username` = :username AND `password` = :password";
$stmt = $pdo->prepare($query);
$stmt->execute(array(
':username' => $_POST['username'],
':password' => $password_hash
));
$row = (bool) $stmt->fetch();
if (!$rows)
{
echo '<p class="warning">Fel användarnamn/lösenords kombination.</p>';
} else {
$_SESSION['user_id'] = $row;
header('Location: index.php');
exit;
}
} else {
echo '<p class="warning">Du måste fylla i ett användarnamn och lösenord</p>';
}
}
?>
<!--- LOGIN FORM --->
<div id="form-column">
<p>You need to be loggedin.</p>
<p>Fill out username and password.</p>
<form action="<?php echo $current_file; ?>" method="POST">
Användarnamn: <input type="text" name="username">
Lösenord: <input type="password" name="password">
<input type="submit" value="Log in">
</form>
</div>
这是core.inc.php
<?php
ob_start();
session_start();
$current_file = $_SERVER['SCRIPT_NAME'];
if (isset($_SERVER['HTTP_REFERER'])&&!empty($_SERVER['HTTP_REFERER'])) {
$http_referer = $_SERVER['HTTP_REFERER'];
}
function loggedin () {
if (isset($_SESSION['user_id'])&&!empty($_SESSION['user_id'])) {
return true;
} else {
return false;
}
}
function getuserrow ($row) {
$sql ="SELECT * FROM USERDATA where id = ?".$_SESSION['user_id']."'";
global $pdo;
$stmt = $pdo->prepare($sql);
$stmt->execute(array($_POST['username']));
$row = $stmt->fetch();
}
?>
这是connect.inc.php
<?php
$dsn = "mysql:host=localhost;dbname=users;charset=utf8";
$opt = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
);
$pdo = new PDO($dsn,'root','', $opt);
?>