<?php
include("../../include/session.php");
include("../../include/db.php");
if(!$session -> isAdmin()){
	header("Location: ../../main.php");
}else{
//	$wetName = mysql_real_escape_string($_POST['wetName']);
	foreach($_POST as $key => $value){
		$fieldArray[$key] = mysql_real_escape_string($value);
		$fields = mysql_list_fields('Cody', 'recipiewet');
		$columns = mysql_num_fields($fields);
		for ($i = 0; $i < $columns; $i++) {
			$field_array[] = mysql_field_name($fields, $i);
		}
		if (!in_array($key, $field_array)) {
			if ($key != "submitok") {
				if (preg_match("/Price/i", $key)) {
					$bleh = str_replace("Price", "", $key);
					$query1 = "ALTER TABLE nam_perwetprice ADD $bleh double(10,2)";
					execsql($query1);
				} else {
					$query = "ALTER TABLE nam_recipiewet ADD $key double(10,4)";
					$result = execsql($query);
				}
			}
		}
	}
	
	$columns = "";
	$values = "";
	$q ="";
	foreach($fieldArray as $key => $value){
		if ($key != "submitok" && $value != ""){
			if (preg_match("/Price/i", $key)) {
				$bleh = str_replace("Price", "", $key);
				$pColumns .= "$bleh,";
				$pValues .= "'$value',";
			}else{
				$columns .= "$key,";
				$values .= "'$value',";
			}
		}
	}
	$q = "INSERT INTO nam_recipiewet ($columns id) VALUES ($values 'null')";
	$q1 = "INSERT INTO nam_perwetprice ($pColumns id) VALUES ($pValues 'null')";
//	echo $q1;
		$r = execsql($q);
		execsql($q1);
		if(!$r){
			echo "you fail";
		}else { 
			header("Location: ../productionMenu.php"); 
		}

}


?>
