Well, I have a code that just won't run. It says it has a syntax error, but I've been looking at this code for 20 minutes and haven't found any. Could you guys plese tell me if something is wrong?

// $anio holds the name of my table.
$query="INSERT INTO $anio 
        (nombre, RFC, factura, importe, IVA, total) 
        VALUES
        ('$nombre', '$RFC', '$factura', $importe, $IVA, $total)";

//This echo returns my query, wich seems perfect to me.
echo $query;

//This is the part that displays an error. I'll show it to you in a moment.
mysql_query($query) or die("Operation could not be performed: " . mysql_error() );

And this is what I get when I run the script:

//this is the $query that i echoed a little bit ago:
INSERT INTO 2012 (nombre, RFC, factura, importe, IVA, total) 
VALUES ('Prueba', 'RFCprueba', '25487', 100.4, 16.064, 116.464)

//this is the mysql_error():
Operation could not be performed:  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 '2012 (nombre, RFC, factura, importe, IVA, total) VALUES ('Prueba', ' at line 1

the values inserted are just test values.

Sorry to make a threadn on such a silly matter, but I'm lost. I realli think this should work.

Recommended Answers

All 2 Replies

a tablename that consists only of digits may need to be encapsulated with `backtick`s - look here

Oh my god, I feel so stupid. Thanks! :)
You really helped me n_n

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.