<?
$model=$_POST["model"];
$type=$_POST["REGION1"];
$groups=$_POST["STATE1"];
$name=$_POST["name"];
$weight=$_POST["weight"];
$amount=$_POST["amount"];
$level=$_POST["level"];

$user="cp037684_tbadm";
$password="siamnovaTho1220!";
$database="cp037684_tbadm";
$c = mysql_connect("localhost",$user,$password);

mysql_query("SET character_set_results=tis620");
mysql_query("SET character_set_client=''tis620''");
mysql_query("SET character_set_connection=''tis620''");
mysql_query("collation_connection = tis620_thai_ci");
mysql_query("collation_database = tis620_thai_ci");
mysql_query("collation_server = tis620_thai_ci");
 
@mysql_select_db($database) or die( "Unable to select database");
mysql_db_query($database,"SET NAMES tis620");// 

$q="UPDATE `product` SET   `type` = '$type' ,`groups` = '$groups' ,`model` = '$model' ,`weight` = '$weight' ,`amount` = '$amount' ,`level` = '$level' ,`timerec` = NOW(), `name` = '$name' WHERE `id` = '$id' LIMIT 1";

if (!$RES = mysql_query($q, $c)) die("มีปัญหากับ : ". $q);
echo "edit  - $q";
if (isset($HTTP_POST_FILES["file1"])) {
$SrcPathFile = $HTTP_POST_FILES["file1"]["tmp_name"];
$SrcFileType = $HTTP_POST_FILES["file1"]["type"];
$DstFileName = $HTTP_POST_FILES["file1"]["name"];

if  ($DstFileName!="")
{

$q="DELETE FROM `file` WHERE  `id` = '$id' ";
if (!$RES = mysql_query($q, $c)) die("มีปัญหากับ : ". $q);
$q="DELETE FROM `filedata` WHERE  `masterid` = '$id' ";
if (!$RES = mysql_query($q, $c)) die("มีปัญหากับ : ". $q);

clearstatcache();
$time = filemtime($SrcPathFile);
$storedate = date("Y-m-d H:i:s", $time);
if (file_exists($SrcPathFile)) {
$q = "insert into file (id,datatype, name, size, filedate) values ('";
$q .= $id . "', '" . $SrcFileType . "', '" . $DstFileName . "', " . filesize($SrcPathFile);
$q .= ", '" . $storedate . "')";
if (!$RES = mysql_query($q, $c)) die("มีปัญหากับ : ". $q);
$fileid = mysql_insert_id($c);
$fp = fopen($SrcPathFile, "rb");
while (!feof($fp)) {
  $binarydata = addslashes(fread($fp, 65535));
  $q = "insert into filedata (masterid, filedata) values (";
  $q .= $fileid . ", '" . $binarydata . "')";
  if (!mysql_query($q, $c)) die("มีปัญหากับ : ". $q);
}
fclose($fp);
echo "Upload Complete<br>";
} } }
			 
?>
