我的SQL语句不起作用......
这是我的变量:
$email="test@test.com";
这些陈述不起作用:
$sql = "SELECT * FROM table WHERE email = $email";
$sql = 'SELECT * FROM table WHERE email = ' . $email;
1064您的SQL语法有错误;查看与MySQL服务器版本对应的手册,以便在第1行的“@ test.com”附近使用正确的语法
但是如果我使用字符串而不是变量,它可以工作:
$sql = "SELECT * FROM table WHERE email = 'test@test.com'";
我的陈述有什么问题? 谢谢!
答案 0 :(得分:1)
请在mysql中转义字符串
$sql = "SELECT * FROM table WHERE email = $email";
$sql = 'SELECT * FROM table WHERE email = ' . $email;
这应该有效
$sql = "SELECT * FROM table WHERE email = '$email'";
答案 1 :(得分:0)
table是一个关键字,所以可以像这样写
$sql = "SELECT * FROM `table` WHERE email='$email'";
答案 2 :(得分:-1)
$this->db->where('email', $this->input->post('email'));
$query =$this->db->get($this->user);
//$sql = "SELECT * FROM user WHERE email = '$email'";
if($query->num_rows == 1)
{
return true;
}
else
{
return false;
}
} }