mysql_query("INSERT INTO accounting(transid, unixtime, username, description, amount, type, time) VALUES('$randomtransid', '0', '$yti', 'BLVD Offer Completion', '$theamount', 'points', '$dateandtime')");
The example code above is my MySQL query but it does not get added into the MySQL database every time I refresh the page...
What can I do?
============= SOLVED:
After adding "mysql_error();",
this is the error:
Query failed: Duplicate entry ... for key 'uniqueness'
I fixed this by changing the structure of my database table.
Thanks
=============
You need a space after your table name. Otherwise it looks like a function.
mysql_query("INSERT INTO accounting(transid, unixtime, username, description, amount, type, time) VALUES('$randomtransid', '0', '$yti', 'BLVD Offer Completion', '$theamount', 'points', '$dateandtime')");
^^^^^^^
HERE
Should be:
mysql_query("INSERT INTO accounting (transid, unixtime, username, description, amount, type, time) VALUES('$randomtransid', '0', '$yti', 'BLVD Offer Completion', '$theamount', 'points', '$dateandtime')");
A few notes:
If you checked for error in your code you would have caught this quickly and easily. Always look for and handle errors. In your case a call to mysql_error()
would have done the trick.
You shouldn'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.
Since I can't see you handling this explicitly in your code I must assume you are wide open to SQL injections.