AzaraelIshanti Posted December 10, 2012 Share Posted December 10, 2012 (edited) I have no doubt that I'm missing something obvious, but I'm getting an infrequent syntax error from the simplest of MySQL queries. Background info: Table "profiles" has two columns "id" (int 2) and "joindate" (int 10). Stored as an integer on the table 'cause I have no use for the date there, I manipulate it elsewhere in the program. Anyway, not relevant... Here's the query. $rightnow is getting the time and $id refers to the correct (tested this already...) id of the player trying to update their profile. $rightnow = time(); $mysql_query2 = "INSERT INTO profiles (id, joindate) VALUES ($id, $rightnow)"; 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 ' 1355098639)' Needless to say I'm extremely annoyed, it seems quite straightforward. I have also run into other random errors with the final value of random simple MySQL queries. Happens about once a month and it's completely inexplicable. I end up COPYing and PASTEing another unrelated MySQL call (which to the eye looks identical...) and simply replace the COPYed values with the new values I'm trying to pass...and it works! But...the end result is, as far as I can tell, identical. But copying a working query and replacing values work, writing a new one doesn't...so I'm doing SOMETHING wrong? Or my MySQL server just hates me... HELP! I'm annoyed! Edited December 10, 2012 by AzaraelIshanti Quote Link to comment Share on other sites More sharing options...
Barand Posted December 10, 2012 Share Posted December 10, 2012 What is your actual code? That error message shows a single quote. Quote Link to comment Share on other sites More sharing options...
AzaraelIshanti Posted December 10, 2012 Author Share Posted December 10, 2012 The actual code is posted in the thread. Do you need more of it? I thought I posted the relevant bits. That's straight from the PHP document. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 10, 2012 Share Posted December 10, 2012 I'm going to guess that $id has no value. If the `id` field in the database is an autoincrement field, you can just leave it out of the query entirely. Why use INT(2) by the way? Quote Link to comment Share on other sites More sharing options...
AzaraelIshanti Posted December 10, 2012 Author Share Posted December 10, 2012 The field in this table is not auto-increment, it's based off the auto-increment from another table Int 2 'cause...I'm not planning on having more than 99 users? $id definitely has a value, I even had it echo the whole query, the $id is definitely storing an integer value. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 10, 2012 Share Posted December 10, 2012 You've say echoed the whole query when the error occurs? Post that as well. INT(2) only sets the display width, not the number of digits the field can hold, a single '1' would be padded with a zero to read '01'. Quote Link to comment Share on other sites More sharing options...
AzaraelIshanti Posted December 10, 2012 Author Share Posted December 10, 2012 Well, I am fairly an idiot, you are right. I must've printed the ID from a different page for a similar process. One of the previous MySQL calls was failing and not setting up the id correctly, so yea, it didn't get a value, was trying to pass a ' '. But, while we're both here, I was under the impression that int(2) referred to the number of digits? If not, why does it not have 01 as the value on the database? It just seems to say 1... Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 10, 2012 Share Posted December 10, 2012 If you don't have it set to zerofill it won't show. Quote Link to comment Share on other sites More sharing options...
Christian F. Posted December 10, 2012 Share Posted December 10, 2012 If you only want 99 users (or less), and want to save on space, then you should be using TINYINT instead. Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 10, 2012 Share Posted December 10, 2012 He's got 99 users but a hacker ain't one!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.