以下是获取的mysql错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECY * FORM user WHERE username='' AND password='' LIMIT 1' at line 1
这是我的代码:
<?php
session_start();
include_once("connect.php");
if (isset($_POST['username'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECY * FORM users WHERE username='".$username."' AND password='".$password."' LIMIT 1";
$res = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($res) == 1) {
$row = mysql_fetch_assoc($res);
$_SESSION['uid'] = $row ['id'];
$_SESSION['username'] = $row ['username'];
header("Location: index.php");
exit();
} else {
echo "Invalid login information. Please return to the previous page.";
exit();
}
}
?>
有人可以帮助我吗? :) 我不知道我在这里工作的是什么,无法找到错误。
答案 0 :(得分:2)
SELECY
是印刷错误,请尝试:
SELECT
答案 1 :(得分:1)
$sql = "SELECY * FORM users
WHERE username='".$username."'
AND password='".$password."'
LIMIT 1";
将SELECY
更改为SELECT
,将FORM
更改为FROM
。
正确的查询应该是:
$sql = "SELECT * FROM users
WHERE username='".$username."'
AND password='".$password."'
LIMIT 1";