SHOW TABLES LIKE上的语法错误

时间:2016-05-03 05:16:39

标签: mysql php-5.5

我不明白为什么在这个问题上说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 ''User_notifications''

<?php
include 'constants.php';
$username=$_POST['username'];
$notiftable=$username.'_notifications';
$con=new mysqli('',databaseuser,databasepassword,database);
if($con)
{
    $q="SHOW TABLES LIKE '$notiftable'";

1 个答案:

答案 0 :(得分:1)

您的表名User_notifications正在进行双重转义(即它被转义两次)。这很有可能发生,因为PHP函数已经在逃避它,而你正在第二次这样做。尽量不要自己逃避表名,即:

 $q = "SHOW TABLES LIKE $notiftable";