<?
	// RECORD CREATOR
	if (isset($_POST['insert'])) {
		
		$query = "SELECT * FROM ".$table;
		$mysqldb1->query($query);
		
		$insertSQL = "";
		for ($i = 0; $i < $mysqldb1->numberFields(); $i++) {
			$insertSQL .= $mysqldb1->fieldName($i)."='".clean($_POST[$mysqldb1->fieldName($i)])."', ";
		}
		$insertSQL = rtrim($insertSQL, ", ");
		
		$query = "INSERT INTO ".$table." SET ".$insertSQL;
		if ($debug) { fb($query); }
		$row2 = $mysqldb2->fetchObject();
		
		$result_write_record = $mysqldb2->query($query);
		$id = mysql_insert_id();
		
		if ($result_write_record) {
			$log .= '<div class="success">[RECORD: ID-'.$id.' CREATED]</div>';
			$query = "SELECT * FROM ".$table." WHERE id=".$id;
			$mysqldb1->query($query);
			$ROW = $mysqldb1->fetchArray();
		} else {
			$log .= '<div class="error">ERROR! [RECORD: ID-'.$id.' FAILED] (record could not be created)</div>';
		}
	}
	
	// RECORD UPDATER
	if (isset($_POST['update'])) {
		
		$query = "SELECT * FROM ".$table;
		$mysqldb1->query($query);
		
		$updateSQL = "";
		for ($i = 0; $i < $mysqldb1->numberFields(); $i++) {
			$updateSQL .= $mysqldb1->fieldName($i)."='".clean($_POST[$mysqldb1->fieldName($i)])."', ";
		}
		$updateSQL = rtrim($updateSQL, ", ");
		
		$query = "UPDATE ".$table." SET ".$updateSQL." WHERE id = '".$id."'";
		if ($debug) { fb($query); }
		$row2 = $mysqldb2->fetchObject();
		
		$result_write_record = $mysqldb2->query($query);
		
		if ($result_write_record) {
			$log .= '<div class="success">[RECORD: ID-'.$id.' UPDATED]</div>';
			$query = "SELECT * FROM ".$table." WHERE id=".$id;
			$mysqldb1->query($query);
			$ROW = $mysqldb1->fetchArray();
		} else {
			$log .= '<div class="error">ERROR! [RECORD: ID-'.$id.' FAILED] (record could not be updated)</div>';
		}
	}
?>