SQL 语法错误; [英] error in your SQL syntax;
问题描述
我收到此错误,尽管我尝试将新的更改为我仍然遇到此问题,谁能告诉我我该怎么办.我已经完全更改了页面和数据库,但仍然出现相同的错误.
hi i am getting this error though i tried to change the new to i am stil getting this problem can anyone tell me what should i do. I have completely changed the page also database but still same error.
错误>
您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以获取在calendar_admin"附近使用的正确语法,其中教师_id='ipcst123' 和密码='a141c47927929bc2d1fb6'在第 1 行
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''calendar_admin' WHERE teacher_id='ipcst123' and password='a141c47927929bc2d1fb6' at line 1
我的代码>
<?php
$username=$_POST['teacherId'];
$password=$_POST['password'];
$password=md5($password);
try {
$bdd = new PDO('mysql:host=localhost;dbname=XXX', 'XXX', 'XXX');
} catch(Exception $e) {
exit('Unable to connect to database.');
}
$query ="SELECT * FROM 'calendar_admin' WHERE teacher_id="."'".$username."' and password="."'".$password."' ";
$resultat = $bdd->query($query) or die(print_r($bdd->errorInfo()));
$res = $resultat->fetchAll(PDO::FETCH_ASSOC);
foreach($res as $result){
$pass=md5($password);
$user=$result["teacher_id"];
if ($pass==$result["password"]&& $username == $user ){
echo "login Success";
session_start();
$_SESSION['teacher_id'] = $username;
header('Location:/addEvents.php');
}else{
header('Location:/login.php');
//echo "Incorrect Password";
}
}
推荐答案
列名和表名周围必须是反引号,而不是单引号.如果名称不是来自保留字(或空格、连字符或任何其他 MySQL 会尖叫的东西,@Fred -ii- 在下面的评论中),则无所谓:
Around column and table names has to be backticks, not single quotes. O rnothing if the names aren't from reserved words (or spaces, or hyphens, or anything else that MySQL will scream about, @Fred -ii- in comments below):
`calendar_admin`
完整查询:
$query ="SELECT *
FROM `calendar_admin`
WHERE teacher_id = '" . $username . "' AND
password = '" . $password . "'";
不要忘记从用户输入中转义数据.
Don't forget to escape data from user inputs.
这篇关于SQL 语法错误;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!