001.
<?
002.
ob_start();
003.
session_start();
004.
if
(
$_SESSION
[
"adminlogin"
]==
""
)
005.
{
006.
header(
'location:login.php'
);
007.
exit
();
008.
}
009.
require
(
"config.php"
);
010.
require
(
"function.php"
);
011.
012.
013.
if
(
$_GET
[
"Action"
]==
"Save"
)
014.
{
015.
$realname
=
$HTTP_POST_FILES
[
'fileupload'
][
'name'
];
016.
$str
=
substr
(
$realname
,-3,3);
017.
if
(
is_uploaded_file
(
$HTTP_POST_FILES
[
'fileupload'
][
'tmp_name'
]))
018.
{
019.
copy
(
$HTTP_POST_FILES
[
'fileupload'
][
'tmp_name'
],
"./image/$realname"
);
020.
$url
=
"image/$realname"
;
021.
$filename
=
$HTTP_POST_FILES
[
'fileupload'
][
'name'
];
022.
$size
=
$HTTP_POST_FILES
[
'fileupload'
][
'size'
]/1024/1024;
023.
$size1
=number_format(
$size
,3);
024.
}
025.
else
026.
{
027.
echo
"Upload not complete"
;
028.
};
029.
$sql_up
=
"update nutritionfact set ProductID='$_POST[txtpid]', ProductName='$_POST[txtprod]', Serving_Size='$_POST[txtserv]', Times='$_POST[txttime]', Energy='$_POST[txtener]', Sugars='$_POST[txtsuga]', Total_Fat='$_POST[txttota]', Sodium='$_POST[txtsodi]', Fig='$url' where ProductID='$_GET[ProductID]'"
;
030.
$dbquery_up
= mysql_query(
$sql_up
)
or
die
(mysql_error());
031.
echo
"<script language='JavaScript'>"
;
032.
echo
"alert('แก้ไขข้อมูลเรียบร้อยแล้ว');"
;
033.
echo
"window.location='update_admin.php';"
;
034.
echo
"</script>"
;
035.
}
036.
037.
?>
038.
<html>
039.
<title>Edit Product's Data</title>
040.
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=windows-874"
>
041.
<script language=
"JavaScript"
src=
"editor.js"
></script>
042.
<script type=
"text/javascript"
>
043.
function
senddata()
044.
{
045.
if
(document.getElementById(
'txtpid'
).value.length == 0)
046.
{
047.
alert (
'ระบุรหัสผลิตภัณฑ์ด้วยค่ะ'
);
048.
return
false;
049.
}
050.
document.getElementById(
'submit'
).disabled = true;
051.
return
true;
052.
}
053.
function
AddOk(pathfile)
054.
{
055.
document.getElementById(
'fileupload'
).value =
""
;
056.
document.getElementById(
'showdetail'
).innerHTML =
'เพิ่มข้อมูลเสร็จเรียบร้อยแล้ว'
;
057.
document.getElementById(
'submit'
).disabled = false;
058.
document.getElementById(
'AddPForm'
).reset();
059.
return
true;
060.
}
061.
</script>
062.
<div align=
"center"
><br>
063.
<?
064.
065.
$result
=select(
"nutritionfact"
,
"where 1=1 and ProductID='"
.
$_GET
[
"ProductID"
].
"'"
);
066.
if
(!
$result
)
067.
{
068.
header(
"location:update_admin.php"
);
069.
}
070.
071.
?>
072.
<form name=
"frm<?=$i;?>"
id=
"AddPForm"
method=
"post"
action=
"<?=$_SERVER['PHP_SELF'];?>?ProductID=<?=$_GET["
ProductID
"];?>&Action=Save"
enctype=
"multipart/form-data"
onSubmit=
"return checkvalue()"
>
073.
<table cellspacing=1 cellpadding=3 width=
"56%"
bgcolor=#CCCCCC border=0 align=
"center"
height=
"10"
>
074.
<tbody>
075.
<tr bgcolor=#e5e5e5>
076.
<td bgcolor=
"#FFFFFF"
> <script language=
"Javascript1.2"
><!--
077.
_editor_url =
""
;
078.
var
win_ie_ver = parseFloat(navigator.appVersion.split(
"MSIE"
)[1]);
079.
if
(navigator.userAgent.indexOf(
'Mac'
) >= 0) { win_ie_ver = 0; }
080.
if
(navigator.userAgent.indexOf(
'Windows CE'
) >= 0) { win_ie_ver = 0; }
081.
if
(navigator.userAgent.indexOf(
'Opera'
) >= 0) { win_ie_ver = 0; }
082.
if
(win_ie_ver >= 5.5) {
083.
document.write(
'<scr'
+
'ipt src="'
+_editor_url+
'editor.js"'
);
084.
document.write(
' language="Javascript1.2"></scr'
+
'ipt>'
);
085.
}
else
{ document.write(
'<scr'
+
'ipt>function editor_generate() { return false; }</scr'
+
'ipt>'
); }
086.
087.
<script language=
"JavaScript"
>
088.
function
checkvalue()
089.
{
090.
091.
092.
}
093.
</script>
094.
<table width=
"100%"
border=
"0"
cellspacing=
"2"
cellpadding=
"2"
>
095.
<tr>
096.
<td width=
"34%"
> </td>
097.
<td width=
"66%"
> </td>
098.
</tr>
099.
<tr>
100.
<td valign=
"top"
><font size=
"+1"
>Product's ID</font></td>
101.
<td><input name=
"txtpid"
type=
"text"
class
=
"txtbox"
id=
"txtpid"
value=
"<?=$result["
ProductID
"];?>"
maxlength=
"20"
readonly=
"true"
>
102.
</td>
103.
</tr>
104.
<tr>
105.
<td valign=
"top"
><font size=
"+1"
>Product's Name</font></td>
106.
<td><input name=
"txtprod"
type=
"text"
class
=
"txtbox"
id=
"txtprod"
value=
"<?=$result["
ProductName
"];?>"
size=
"16"
maxlength=
"20"
>
107.
</td>
108.
</tr>
109.
<tr>
110.
<td valign=
"top"
><font size=
"+1"
>Serving size</font></td>
111.
<td><input name=
"txtserv"
type=
"text"
class
=
"txtbox"
id=
"txtserv"
value=
"<?=$result["
Serving_Size
"];?>"
size=
"16"
maxlength=
"20"
></td>
112.
</tr>
113.
<tr>
114.
<td valign=
"top"
><font size=
"+1"
>Times</font></td>
115.
<td><input name=
"txttime"
type=
"text"
class
=
"txtbox"
id=
"txttime"
value=
"<?=$result["
Times
"];?>"
size=
"16"
maxlength=
"20"
>
116.
ครั้ง </td>
117.
</tr>
118.
<tr>
119.
<td valign=
"top"
><font size=
"+1"
>Energy</font></td>
120.
<td><input name=
"txtener"
type=
"text"
class
=
"txtbox"
id=
"txtener"
value=
"<?=$result["
Energy
"];?>"
size=
"16"
maxlength=
"20"
> กิโลแคลอรี</td>
121.
</tr>
122.
<tr>
123.
<td valign=
"top"
><font size=
"+1"
>Sugars</font></td>
124.
<td><input name=
"txtsuga"
type=
"text"
class
=
"txtbox"
id=
"txtsuga"
value=
"<?=$result["
Sugars
"];?>"
size=
"16"
maxlength=
"20"
>
125.
กรัม</td>
126.
</tr>
127.
<tr>
128.
<td valign=
"top"
><font size=
"+1"
>Total Fat</font></td>
129.
<td><input name=
"txttota"
type=
"text"
class
=
"txtbox"
id=
"txttota"
value=
"<?=$result["
Total_Fat
"];?>"
size=
"16"
maxlength=
"20"
>
130.
กรัม</td>
131.
</tr>
132.
<tr>
133.
<td valign=
"top"
><font size=
"+1"
>Sodium</font></td>
134.
<td><input name=
"txtsodi"
type=
"text"
class
=
"txtbox"
id=
"txtsodi"
value=
"<?=$result["
Sodium
"];?>"
size=
"16"
maxlength=
"20"
>
135.
มิลลิกรัม </td>
136.
137.
</tr>
138.
<tr>
139.
<td valign=
"top"
><font size=
"+1"
>รูปสินค้า</font></td>
140.
<td><input name=
"fileupload"
type=
"file"
class
=
"txtbox"
id=
"fileupload"
value=
"<?=$result["
Fig
"];?>"
></td>
141.
142.
</tr>
143.
</tr>
144.
<tr>
145.
<td></td>
146.
<td><input name=
"Submit"
type=
"submit"
class
=
"button"
value=
"Done"
>
147.
<input name=
"Cancel"
type=
"button"
class
=
"button"
id=
"Cancel"
value=
"Cancle"
onClick=
"window.location='update_admin.php';"
></td>
148.
</tr>
149.
<tr>
150.
<td> </td>
151.
<td> </td>
152.
</tr>
153.
<tr>
154.
<td> </td>
155.
<td> </td>
156.
</tr>
157.
</table></td>
158.
</tr>
159.
160.
</tbody>
161.
</table>
162.
</form>