Inserting repeat rows problem

Really not sure why it is doing this but I am basically inserting a draft post when a user clicks on create a new post.

It goes through my insert_post function which goes into my insert_data function which normally works fine but in this particular case, and I cannot tell why, it is inserting the default post but then repeating this up to two times, with a date incremented by 1-6 seconds.

As a test I’ve followed it’s path through to the insert_data, echoed the query being sent and hten set it to die immediately after the insert. Doing this gives 2 entries, not doing it does 3 so something is happening elsewhere as well, but somehow it is inserting two rows before this point with different dates despite the date being set before getting to this point based on the current time.

Additionally since I have set it to echo the query I would expect it to show up 3 times but it doesn’t, only the once, the original with the time corresponding to the first of the 2-3 posts. I also call the insert_id from the last immediate post to allow me to edit that post and this ID too corresponds to the first, correct post. So I’m really lost here.

This is my query:

INSERT INTO `posts` (`post_title`,`post_content`,`date_created`,`post_author`,`post_parent`,`date_modified`,`post_description`,`post_status`,`post_guid`,`post_name`,`post_comments`,`post_type`,`menu_order`) 

VALUES ('Auto Draft','',1320197307,1,'0',1320197307,'','auto-draft','','auto-draft','open','post','0')

And the php code

$fields = array_keys($data);				//THIS CONTAINS THE FIELD NAMES FOR THE DATABASE
		$formatted_fields = array();
		foreach ( $fields as $field ) {
			//if ( !empty($format) )
			//	$form = ( $form = array_shift($formats) ) ? $form : $format[0];
			if ( isset($data[$field]) )
					if(is_numeric($data[$field]) && substr($data[$field], 0, 1) != '0') 
				{ 
					$form = $data[$field];
				}
				else {   	
					$form = "'".$data[$field]."'";
					}
			$formatted_fields[] = $form;
		}
		echo "INSERT INTO `$table` (`" . implode( '`,`', $fields ) . "`) VALUES (" . implode( ",", $formatted_fields ) . ")<br/>";
		mysql_query("INSERT INTO `$table` (`" . implode( '`,`', $fields ) . "`) VALUES (" . implode( ",", $formatted_fields ) . ")") or die(mysql_error());
		die();

And an image of what this produces.

i feel quite confident in saying that if you run this query outside of php, i.e. directly in mysql, that it will insert only one row – guaranteed

it sure sounds like you have a php problem, not a mysql problem (the forum you posted in)