[英]Showing a syntax error eventhough it works when use the query in sql
$query ="SELECT * FROM book1 WHERE";
foreach ($terms as $each) {
$i++;
if($i == 1){
$query.="keywords LIKE '%$each%'";
}
else{
$query.="OR keywords LIKE '%$each%'";
}
}
$hello=mysql_query($query);
if(mysql_num_rows($hello)>=1)
{
while($i= mysql_fetch_assoc($query))
{
echo ' ';
echo '<h2><a href="'.$i['link'].'">'.$i['bname'].'</a></h2>';
}
}
The following error shows up when i run the code 当我运行代码时出现以下错误
You have an error in your SQL syntax; 您的SQL语法有误; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'LIKE '%paul%'' at line 1
检查与您的MariaDB服务器版本相对应的手册以获取正确的语法,以在第1行的'LIKE'%paul%'附近使用
but the same query gave results when i ran it on mysql Can someone help me find the problem with my code ? 但是当我在mysql上运行它时,相同的查询给出了结果。有人可以帮我找到代码问题吗?
Need space at 需要的空间
if($i == 1){
$query.=" keywords LIKE '%$each%'";
^^^
}
else{
$query.=" OR keywords LIKE '%$each%'";
^^^
}
Otherwise query become 否则查询成为
SELECT * FROM book1 WHEREkeywords...
Missing ;
失踪
;
at $hello=mysql_query($query);
在
$hello=mysql_query($query);
Note mysql is deprecated instead use mysqli or PDO
注意不建议使用mysql,而应使用mysqli或PDO
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.