0

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.

Edited by e.patricioparga: additional info

2
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by e.patricioparga
1

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

Edited by adam.adamski.96155

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.