-1

Ok I've been messing with this code for quite a while now and it keeps saying I have an unexpected T_VARIABLE on line 54. Anyone know what it is and how to fix?

// 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());
Veloncia
  • 117
  • 3
  • 13
  • 1
    could you highlight line 54 please – pulsar Jul 20 '13 at 10:23
  • I put **LINE 54** in front of line 54 – Veloncia Jul 20 '13 at 10:26
  • May be error here...write this way->Values('".$key.",'".$value."') $registerid = mysql_query("INSERT INTO downloadkey (uniqueid,timestamp) VALUES("$key","$time")") or die(mysql_error()); – Butani Vijay Jul 20 '13 at 10:26
  • 2
    Now you've had this question answered, forget about MySQL and start learning MySQLi or PDO with prepared statements: you're clearly just starting to learn, so learn the better methods of querying databases, rather than bad methods that you'll have to unlearn later – Mark Baker Jul 20 '13 at 10:26
  • One can't stress @MarkBaker's point enough. Please stop concatenating strings to make queries and start using prepared statements already. – Pranav Negandhi Jul 20 '13 at 10:28

8 Answers8

1

You need to use single quotes instead of double quotes:

$registerid = mysql_query("
INSERT INTO downloadkey (uniqueid,timestamp) 
VALUES('$key','$time')") or die(mysql_error());

The other solution is to concatenate your variables, like so:

$registerid = mysql_query("
INSERT INTO downloadkey (uniqueid,timestamp) 
VALUES(" . $key . "," . $time . ")") or die(mysql_error());

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Zoe
  • 27,060
  • 21
  • 118
  • 148
0

There was Syntax error. The code was broken by the use of double quotes near VALUES("$key","$time")

$registerid = mysql_query("INSERT INTO downloadkey (uniqueid,timestamp) VALUES('$key','$time')") or die(mysql_error());
curious_coder
  • 2,392
  • 4
  • 25
  • 44
0

your insert query looks like it has been broken by the " php is smart enough can read its variable inside the " quotes then no need to wrap you variables in the " when they are already opened

 $registerid = mysql_query("INSERT INTO downloadkey (uniqueid,timestamp)
 VALUES($key,$time)") or die(mysql_error());
M Khalid Junaid
  • 63,861
  • 10
  • 90
  • 118
0

Correct line 54 is

$registerid = mysql_query("INSERT INTO downloadkey (uniqueid,timestamp) VALUES(\"$key\",\"$time\")") or die(mysql_error());

0
**LINE 54**   $registerid = mysql_query("INSERT INTO downloadkey (uniqueid,timestamp) VALUES(\"$key\",\"$time\")") or die(mysql_error());

Escape your quotes.

Pranav Negandhi
  • 1,594
  • 1
  • 8
  • 17
0

This line is the culprit. If you break off a string to insert variables you need to concatenate them

Solution A:

$registerid = mysql_query("INSERT INTO downloadkey (uniqueid,timestamp) VALUES('".$key."','".$time."')") or die(mysql_error());

Solution B

$registerid = mysql_query("INSERT INTO downloadkey (uniqueid,timestamp) VALUES('$key','$time')") or die(mysql_error());

And please don't use deprecated functions like mysql_*

JimL
  • 2,501
  • 1
  • 19
  • 19
0

maybe try:

$registerid = mysql_query("INSERT INTO downloadkey (`uniqueid`,`timestamp`) VALUES('$key','$time')") or die(mysql_error());
pulsar
  • 986
  • 1
  • 9
  • 22
0
$registerid = mysql_query("INSERT INTO downloadkey (uniqueid,timestamp) VALUES("$key","$time")") or die(mysql_error());

Replace with:

$registerid = mysql_query("INSERT INTO downloadkey (uniqueid,timestamp) VALUES('" . $key . "','" . $time . "')") or die(mysql_error());
Johnny Bueti
  • 637
  • 1
  • 8
  • 27