-2

我的脚本有问题:

<?php
include('includes/header.php');
include("includes/config.php");
$email = $_GET['email'];
$key = $_GET['key'];
$email = strip_tags($email); 
$email = trim($email);
$key = strip_tags($key); 
$key = trim($key);
$sql = mysql_query("SELECT * FROM confirm WHERE email = '$email' AND key = '$key' 
ORDER BY id ASC LIMIT 1")or die(mysql_error()); 
while($result = mysql_fetch_array($sql))
{ 
$key2 = $result['key']; 
$email2 = $result['email'];  
}
if($key == $key2 && $email == $email2){
$sql = mysql_query("UPDATE users SET user_confirm = 1 WHERE user_mail = '$email2'")or  
die(mysql_error());
$sql = mysql_query("DELETE FROM confirm WHERE email = '$email2'")or die(mysql_error());
echo "Your account have been activated, and is ready to use!";
}else{
echo 'You have entered wrong key or the key is invalid!';
}
include('includes/footer.php');
?>

'key = (keyvalue here)' 附近出现语法错误

有谁知道我在这里做错了什么?

4

3 回答 3

1

'key' 是 MySQL 中的保留字。

将您的第一个查询更改为以下内容(注意关键字周围的正确引用)

$sql = mysql_query("SELECT * FROM confirm WHERE email = '$email' AND `key` = '$key' ORDER BY id ASC LIMIT 1")or die(mysql_error()); 

更好的解决方案是不使用 mysql 保留字。因此,您可以重命名“确认”表中的“键”列。

这是 MySQL 保留字列表: http: //dev.mysql.com/doc/refman/5.5/en/reserved-words.html

于 2013-03-14T14:08:10.020 回答
1

如果您的列名是“key”,那么问题KEY是 MySQL 5.1 中的旧运算符。您可以在列名周围加上反引号以使其工作

`key` = 'some value'
于 2013-03-14T14:06:13.550 回答
0

将您的列名编辑为 cnf_key ,然后尝试替换下面的 syntex

$sql = mysql_query("SELECT * FROM confirm WHERE email = '$email' AND `cnf_key`= '$key' 
ORDER BY id ASC LIMIT 0,1")or die(mysql_error()); 
于 2013-03-14T14:07:55.387 回答