SQL语法错误MariaDB服务器版本,用于在第1行的"WHERE ID = 4"附近使用的正确语法 [英] SQL syntax error MariaDB server version for the right syntax to use near 'WHERE ID = 4' at line 1

查看:203
本文介绍了SQL语法错误MariaDB服务器版本,用于在第1行的"WHERE ID = 4"附近使用的正确语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这行SQL:

$sql = "SELECT ID, ListStID, ListEmail, Title FROM $entry_database WHERE ID = '". $ReqBookID ."'";
$result = mysqli_query($conn, $sql);

如您所见,如果ID等于用户以表格形式给出的数字(或文本)字符串,那么我将选择条目的ID,ListStID,ListEmail和标题栏".

As you can see, I am selecting an entry's ID, ListStID, ListEmail and Title Column if ID is equal to a string of numbers (or text), which is given by user in a form.

一切正常,编写代码时我没有收到任何语法错误(我正在使用代码编辑器软件.但是,当我在线使用它时,会出现此错误:

Everything is ok, and I don't get any syntax error when I write the code (I am using a code editor software. However, when I use it online, I get this error:

错误:SELECT ID,ListStID,ListEmail,WHERE ID ='4'的标题 您的SQL语法有错误;检查对应的手册 您的MariaDB服务器版本,以在'WHERE ID附近使用正确的语法 =第1行的'4'

Error: SELECT ID, ListStID, ListEmail, Title FROM WHERE ID = '4' 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 'WHERE ID = '4'' at line 1

我对PHP还是很陌生,我敢肯定我会添加多余的'或,所以如果您能帮助我解决这个问题,我将非常感谢.我已经尝试了类似问题的答案,但是没有成功了.

I am very new to PHP, and I'm sure I am either adding extra ' or ", so I would really appreciate it if you could help me with this issue. I have tried the answers for similar questions, but no success yet.

推荐答案

您有空的$entry_database变量.如您所见,错误:ListEmail, Title FROM WHERE ID FROM WHERE 之间应该是表的名称. SELECT的正确语法:

You have empty $entry_database variable. As you see in error: ListEmail, Title FROM WHERE ID bewteen FROM and WHERE should be name of table. Proper syntax of SELECT:

SELECT columns FROM table [optional things as WHERE/ORDER/GROUP/JOIN etc]

以您的方式应该变成:

SELECT ID, ListStID, ListEmail, Title FROM some_table_you_got WHERE ID = '4'

这篇关于SQL语法错误MariaDB服务器版本,用于在第1行的"WHERE ID = 4"附近使用的正确语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆