好的,我现在已经搞乱了这段代码了很长一段时间,它一直在说我在第54行有一个意想不到的T_VARIABLE。有人知道它是什么以及如何解决?
// Write the key and activation time to the database as a new row
**LINE 54** $registerid = mysql_query("INSERT INTO downloadkey (uniqueid,timestamp) VALUES("$key","$time")") or die(mysql_error());
答案 0 :(得分:1)
您需要使用单引号而不是双引号:
$registerid = mysql_query("
INSERT INTO downloadkey (uniqueid,timestamp)
VALUES('$key','$time')") or die(mysql_error());
另一个解决方案是连接变量,如下所示:
$registerid = mysql_query("
INSERT INTO downloadkey (uniqueid,timestamp)
VALUES(" . $key . "," . $time . ")") or die(mysql_error());
Please, don't use
mysql_*
functions in new code。它们不再被维护and are officially deprecated。请参阅red box?转而了解prepared statements,并使用PDO或MySQLi - this article将帮助您确定哪个。如果您选择PDO here is a good tutorial。
答案 1 :(得分:0)
出现语法错误。在VALUES("$key","$time")
$registerid = mysql_query("INSERT INTO downloadkey (uniqueid,timestamp) VALUES('$key','$time')") or die(mysql_error());
答案 2 :(得分:0)
你的插入查询看起来已经被"
破坏了php足够聪明可以在"
引号内读取它的变量然后在"
时不需要包装变量他们已经打开了
$registerid = mysql_query("INSERT INTO downloadkey (uniqueid,timestamp)
VALUES($key,$time)") or die(mysql_error());
答案 3 :(得分:0)
正确的第54行是
$ registerid = mysql_query(“INSERT INTO downloadkey (uniqueid,timestamp)VALUES(\“$ key \”,\“$ time \”)“)或 死亡(mysql_error());
答案 4 :(得分:0)
**LINE 54** $registerid = mysql_query("INSERT INTO downloadkey (uniqueid,timestamp) VALUES(\"$key\",\"$time\")") or die(mysql_error());
逃避你的报价。
答案 5 :(得分:0)
这条线是罪魁祸首。如果中断字符串以插入变量,则需要将它们连接起来
解决方案A:
$registerid = mysql_query("INSERT INTO downloadkey (uniqueid,timestamp) VALUES('".$key."','".$time."')") or die(mysql_error());
解决方案B
$registerid = mysql_query("INSERT INTO downloadkey (uniqueid,timestamp) VALUES('$key','$time')") or die(mysql_error());
请不要使用像mysql _ *
这样的弃用函数答案 6 :(得分:0)
也许试试:
$registerid = mysql_query("INSERT INTO downloadkey (`uniqueid`,`timestamp`) VALUES('$key','$time')") or die(mysql_error());
答案 7 :(得分:0)
$registerid = mysql_query("INSERT INTO downloadkey (uniqueid,timestamp) VALUES("$key","$time")") or die(mysql_error());
替换为:
$registerid = mysql_query("INSERT INTO downloadkey (uniqueid,timestamp) VALUES('" . $key . "','" . $time . "')") or die(mysql_error());