php 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在“离开”附近使用的正确语法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18433105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
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 ''leave''
提问by JJ___
I always get this error when i run my code
当我运行我的代码时,我总是收到这个错误
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 ''leave'' at line 1
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的“离开”附近使用的正确语法
Here is my coding part
这是我的编码部分
<?php
$result = mysql_query("select * from 'leave'");
if ($result == FALSE)
{
die(mysql_error());
}
while($row = mysql_fetch_assoc($result))
{
?>
<tr>
<td><a href = "app_status.php? id = <?php echo $row["Leave_ID"];?>" target = "_blank"></a>Leave ID</td>
<td><?php echo $row["Emp_ID"];?></td>
<td><?php echo $row["Date_Apply"];?></td>
<td><?php echo $row["Leave_Type"];?></td>
<td><?php echo $row["Leave_Start"];?></td>
<td><?php echo $row["Leave_End"];?></td>
<td><?php echo $row["Status"];?></td>
</tr>
<?php
}
?>
回答by Naveen Kumar Alonekar
Don't use single quaots
不要使用单引号
You can try it as
你可以试试
$result = mysql_query("select * from leave");
Or use ` key
或者使用`键
$result = mysql_query("select * from `leave`");
回答by Vahid Hallaji
$result = mysql_query("select * from 'leave'");
//^ ^
Use backtick character ` for table name:
使用反引号字符 ` 作为表名:
$result = mysql_query("select * from `leave`");
回答by T.Todua
possible answers:
可能的答案:
1) Any values which are not numeric will need to be quoted.
1) 任何非数字值都需要引用。
2) Your input data should be cleaned/escaped too before use. You are currently open to SQL injection.
2)您的输入数据在使用前也应该被清理/转义。您目前对 SQL 注入持开放态度。
回答by user3347474
$result = mysql_query("select * from your_db.leave") or die (mysql_error());