byrne86 Posted October 29, 2010 Share Posted October 29, 2010 OK, so iv got a form on a website, it inserts data into an SQL database,it was working until I added some more info to be put in - here is the php and error etc... $firstname = $_POST['firstname']; $surname = $_POST['surname']; $email = $_POST['email']; $thisday = date(d); $thismonth = date(F); $thisyear = date(Y); $thishour = date(H); $thisminute = date(i); $thissecond = date(s); $thismicrosecond = date(u); $query = "INSERT INTO mydb (id, firstname, surname, email, day, month, year, hour, minute, second, microsecond) VALUES ('$Guid', '$firstname', '$surname', '$email', '$thisday', $thismonth', '$thisyear', '$thishour', '$thisminute', '$thissecond', '$thismicrosecond')"; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); That is the php getting the data to put into the SQL database Error in query: INSERT INTO mydb (id, firstname, surname, email, day, month, year, hour, minute, second, microsecond) VALUES ('7DD39B65-C369-7750-F77B-DB4904CCB5DE', 'skjdfhsk', 'sndhofsdi', 'oisdfosos', '28', October', '2010', '17', '10', '18', '000000'). 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 '', '2010', '17', '10', '18', '000000')' at line 1 That is the error I am getting... Can anyone tell me whatis wrong with this please. As I said, it was working, but when I added everything from $thisday to $thismicrosecond inclusive this error was showing when I was trying to enter data into the DB Link to comment https://forums.phpfreaks.com/topic/217159-sql-not-working-no-idea-why/ Share on other sites More sharing options...
mikosiko Posted October 29, 2010 Share Posted October 29, 2010 look here: ...... '$thisday', $thismonth' ...... and then here ....... '28', October' ........ is not the error obvious? Link to comment https://forums.phpfreaks.com/topic/217159-sql-not-working-no-idea-why/#findComment-1127810 Share on other sites More sharing options...
byrne86 Posted October 29, 2010 Author Share Posted October 29, 2010 the missing ' cant believe i missed that..... thanks Link to comment https://forums.phpfreaks.com/topic/217159-sql-not-working-no-idea-why/#findComment-1127814 Share on other sites More sharing options...
Pikachu2000 Posted October 29, 2010 Share Posted October 29, 2010 If I can make suggestion, 99.99% of the time it's better to store the date and time in a datetime field rather than broken up like that. Link to comment https://forums.phpfreaks.com/topic/217159-sql-not-working-no-idea-why/#findComment-1127815 Share on other sites More sharing options...
byrne86 Posted October 29, 2010 Author Share Posted October 29, 2010 iv never used that, are there ay examples about I can look at? Link to comment https://forums.phpfreaks.com/topic/217159-sql-not-working-no-idea-why/#findComment-1127816 Share on other sites More sharing options...
fenway Posted October 30, 2010 Share Posted October 30, 2010 iv never used that, are there ay examples about I can look at? Examples of what? the DATETIME column type? Link to comment https://forums.phpfreaks.com/topic/217159-sql-not-working-no-idea-why/#findComment-1128494 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.