Jump to content

Insterting Datetime string into a mysql table


dexter_sherban

Recommended Posts

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 ?

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

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".

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.