dexter_sherban Posted October 20, 2007 Share Posted October 20, 2007 Hey everyone I have an issue with and insert statement. Im trying to insert the current datetime to a table. Let the code speak for itslef // the date fromat variable $date = date("Y-d-m G:i:s"); if(isset($_POST['map'])){ $map=$_POST['map'];} if(isset($_POST['type'])){ $type=$_POST['type'];} if(isset($_POST['title'])){ $title=$_POST['title'];} // File upload if(isset($_FILES['filename']['name']) && $_POST['decision'] == "replay") { $target_path = "replays/"; $target_path = $target_path . basename( $_FILES['filename']['name']); $_FILES['filename']['tmp_name']; if(move_uploaded_file($_FILES['filename']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['filename']['name']). " has been uploaded<br>"; // Mysql query (where the issue arises) $insert = mysql_query("insert into replays (type, title, filename, author, map, date_time) VALUES ('$type','$title','$target_path','$username','$map','$date')"); if ($insert) { echo "<font color='green'>A query referencing your file has been made</font><br>"; } else { echo "<font color='red'>Notice. Mysql reference failed. The file might not be indexed. Check with admin</font><br>"; } } else { // If the file was not uploaded echo "There was an error uploading the file, please try again!"; } } I keep getting the mysql query fail however if i scrap the date column, it will work. It also works if I have $insert = mysql_query("insert into replays (type, title, filename, author, map, date_time) VALUES ('$type','$title','$target_path','$username','$map','0000-00-00 00:00:00')"); Did I forget to mention anything else that could be relevant? Does anyone have any clues ? Quote Link to comment https://forums.phpfreaks.com/topic/74096-insterting-datetime-string-into-a-mysql-table/ Share on other sites More sharing options...
simcoweb Posted October 20, 2007 Share Posted October 20, 2007 It would be helpful if we knew the actual error. Replace this code: $insert = mysql_query("insert into replays (type, title, filename, author, map, date_time) VALUES ('$type','$title','$target_path','$username','$map','$date')"); with this: $insert = mysql_query("insert into replays (type, title, filename, author, map, date_time) VALUES ('$type','$title','$target_path','$username','$map','$date')") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/74096-insterting-datetime-string-into-a-mysql-table/#findComment-374111 Share on other sites More sharing options...
dexter_sherban Posted October 20, 2007 Author Share Posted October 20, 2007 hhmm, right after i posted this, i did something else... i wrote something similar...im preety sure its the same and my error was : 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 '13:49:09)' at line 1 edit :NONONONONON, thats not it... Field 'rating' doesn't have a default value Now rating is a int in the same table...and I wonder why it cares about its value.I can now fix this, but why woundt it leave it null, cause its not "not null". Quote Link to comment https://forums.phpfreaks.com/topic/74096-insterting-datetime-string-into-a-mysql-table/#findComment-374114 Share on other sites More sharing options...
steve448 Posted October 20, 2007 Share Posted October 20, 2007 Not certain but should: $date = date("Y-d-m G:i:s"); Be: $date = date("Y-m-d G:i:s"); Quote Link to comment https://forums.phpfreaks.com/topic/74096-insterting-datetime-string-into-a-mysql-table/#findComment-374115 Share on other sites More sharing options...
dexter_sherban Posted October 20, 2007 Author Share Posted October 20, 2007 scrap what I just said. the actual error ur asking for is Incorrect datetime value: '2007-20-10 14:02:25' for column 'date_time' at row 1 Quote Link to comment https://forums.phpfreaks.com/topic/74096-insterting-datetime-string-into-a-mysql-table/#findComment-374117 Share on other sites More sharing options...
dexter_sherban Posted October 20, 2007 Author Share Posted October 20, 2007 Success ! Tnx alot guys ! its was wrong datetime format Quote Link to comment https://forums.phpfreaks.com/topic/74096-insterting-datetime-string-into-a-mysql-table/#findComment-374120 Share on other sites More sharing options...
Barand Posted October 20, 2007 Share Posted October 20, 2007 To insert current datetime INSERT INTO table (datetimecol) VALUES (NOW() ) Quote Link to comment https://forums.phpfreaks.com/topic/74096-insterting-datetime-string-into-a-mysql-table/#findComment-374237 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.