|
|
|
ช่วยดูโค้ดนี้หน่อยค่ะ แก้ไขข้อมูลได้เพียงรอบเดียว พอจะแก้ข้อมูลเดิมอีกครั้ง มันไม่สามารถแก้ไขได้ |
|
|
|
|
|
|
|
หน้าฟอร์มแก้ไข
Code (PHP)
<?
session_start();
// ----- µÃǨÊͺ admin ¡è͹à¢éÒÊÙè˹éÒ¹Õé ------------
require_once("check_admin.php");
if (check_admin())
{
//----------------------------------------------------------
$pro_id=$_GET['pro_id'];
require_once("connect.php");
require_once("show_database.php");
echo"<title>:: á¡é䢢éÍÁÙÅÊÔ¹¤éÒ ::</title>";
$result=select_product($pro_id);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
?>
<HTML>
<HEAD>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=tis-620">
<TITLE>:: á¡é䢢éÍÁÙÅÊÔ¹¤éÒ ::</TITLE>
<!----------------------------------------- Full Window-------------------------------------->
<script language="JavaScript1.2">
<!--
//Full Window
top.window.moveTo(0,0);
if (document.all) {
top.window.resizeTo(screen.availWidth,screen.availHeight);
}
else if (document.layersdocument.getElementById) {
if (top.window.outerHeight<screen.availHeighttop.window.outerWidth<screen.availWidth){
top.window.outerHeight = screen.availHeight;
top.window.outerWidth = screen.availWidth;
}
}
//-->
</script>
</HEAD>
<BODY onload="document.add.pro_title.focus();">
<br><br><center><span class="b"><b><u>ÃÒ¡ÒÃá¡é䢢éÍÁÙÅÊÔ¹¤éÒ</u></b></span></center><span class="b"><br>
</span><TABLE align=center border=0 cellPadding=0 cellSpacing=0 width=494>
<TBODY>
<TR>
<TD height=6>
<TABLE border="1" cellSpacing=0 width="100%" bgcolor="#FFFFCC" bordercolordark="black" bordercolorlight="black">
<TR>
<TD height=38 bgcolor="#FFCC33">
<FORM action="editproduct.save.php" method=post name=add enctype="multipart/form-data">
<TABLE align=center border=0 cellPadding=0 cellSpacing=0
width="85%" height="122">
<TR>
<TD width="33%" height="25">
<div align="right">
<font face="MS Sans Serif" size="2"><font color="#000000"><b>ÃËÑÊÊÔ¹¤éÒ</b>
<b>:
</b></font></font></div>
</TD>
<TD height=25 width="67%">
<font face="verdana" size="1"><INPUT TYPE=text NAME="pro_id" size="10" maxlength="10" value='<?=$row["pro_id"]?>' DISABLED>
<INPUT TYPE=HIDDEN NAME="pro_id" size="10" maxlength="10" value='<?=$row["pro_id"]?>'>
</font>
</TD></TR>
<TR>
<TD width="33%" height="25">
<div align="right">
<font face="MS Sans Serif" size="2"><font color="#000000"><b>»ÃÐàÀ·ÊÔ¹¤éÒ</b>
<b>:
</b></font></font></div>
</TD>
<TD height=25 width="67%">
<select name="category" size="1">
<?
//----------------------------- áÊ´§»ÃÐàÀ·Ë¹Ñ§Ê×Í·Ñé§ËÁ´ ------------------------------------
// --- ¤ÓÊÑè§ SQL
$sql2 = "select * from category where cat_name<>'$row[category]' ";
$dbquery2 = mysql_query($sql2);
// --- ËҨӹǹàäÍÃì´·Ñé§ËÁ´
$num_row = mysql_num_rows($dbquery2);
// --- áÊ´§ÃÒ¡ÒûÃÐàÀ·Ë¹Ñ§Ê×Í·Ñé§ËÁ´ã¹µÒÃÒ§ category
$i=0;
while($i < $num_row)
{
$row2 = mysql_fetch_array($dbquery2);
?>
<option value="<? echo $row2['cat_name']; ?>" <?=($row["cat_id"]==$row2["cat_id"] ? ' selected' : '')?>><? echo $row2['cat_name']; ?></option>
<?
$i++;
}
//---------------------------------------------------------------------------------------------------
?>
</select>
</TD></TR>
<TR>
<TD width="33%" height="25">
<div align="right">
<font face="MS Sans Serif" size="2"><font color="#000000"><b>ª×èÍÊÔ¹¤éÒ</b>
<b>:
</b></font></font></div>
</TD>
<TD height=25 width="67%">
<font face="verdana" size="1"><INPUT TYPE=text NAME="pro_title" size="30" value='<?=$row["pro_title"]?>'>
</font>
</TD></TR>
<tr>
<TD width="33%" height="25">
<div align="right">
<font face="MS Sans Serif" size="2"><font color="#000000"><b>ÃÙ»ÀÒ¾</b>
<b>:
</b></font></font></div>
</TD>
<TD height=25 width="67%">
<?
if ($row['pro_image']<>"") {
echo "<img src='images/$row[pro_image]' width='100' height='100' border='0'>";
echo "<br><INPUT TYPE='checkbox' NAME='chkdel' VALUE='1'> źÃÙ»ÀÒ¾ <BR>";
echo "<INPUT NAME='oldfile' TYPE='hidden' VALUE='$row[pro_image]'>";
} else {
echo "<INPUT TYPE='file' NAME='fileupload' size='30' >";
echo "<INPUT TYPE='hidden' name='MAX_FILE_SIZE' value='100000'>";
echo "<INPUT TYPE='hidden' NAME='chkdel' VALUE='0'>";
}
?>
</TD>
</tr>
<TR>
<TD width="33%" height="25">
<div align="right">
<font face="MS Sans Serif" size="2"><font color="#000000"><b>¨Ó¹Ç¹</b>
<b>:
</b></font></font></div>
</TD>
<TD height=25 width="67%">
<font face="verdana" size="1"><INPUT TYPE=text NAME="pro_unit" size="30" maxlength="30" value='<?=$row["pro_unit"]?>'>
</font>
</TD></TR>
<TR>
<TD width="33%" height="25">
<div align="right">
<font face="MS Sans Serif" size="2"><font color="#000000"><b>ÃÒ¤Ò</b>
<b>:
</b></font></font></div>
</TD>
<TD height=25 width="67%">
<p><input type="text" name="pro_price" maxlength="5" size="5" value='<?=$row["pro_price"]?>'> ºÒ·</p>
</TD></TR>
</table>
<table align=center>
<TR>
<TD align=center>
<br><input type="submit" name="formbutton1" value="á¡é䢢éÍÁÙÅ">
</TD>
<TD align=center>
<br><input type="reset" name="formbutton2" value="¡àÅÔ¡¢éÍÁÙÅ">
</TD></FORM>
<td align=center>
<br><input type="button" value="»Ô´Ë¹éÒ¹Õé" onclick="javascript:window.close();">
</td>
</TR></TBODY></TABLE>
</form>
</td>
</tr>
</TBODY></TABLE></TD></TR></TBODY></TABLE>
</BODY></HTML>
<?
} //------------------ ÊÔé¹ÊØ´¡ÒõÃǨÊͺ -----------------------
?>
|
|
|
|
|
Date :
2011-06-17 10:47:53 |
By :
myminthom |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
หน้าบันทึกข้อมูลการแก้ไข
Code (PHP)
<?
session_start();
// ----- µÃǨÊͺ admin ¡è͹à¢éÒÊÙè˹éÒ¹Õé ------------
require_once("check_admin.php");
if (check_admin())
{
//----------------------------------------------------------
$chkdel=$_POST['chkdel'];
$pro_id=$_POST['pro_id'];
$category=$_POST['category'];
$pro_title=$_POST['pro_title'];
$oldfile=$_POST['oldfile'];
$pro_unit=$_POST['pro_unit'];
$pro_price=$_POST['pro_price'];
require_once("connect.php");
require_once("function.php");
if(empty($pro_id)||empty($category)||empty($pro_title)||empty($pro_unit)||empty($pro_price))
{
echo"<center><br>";
echo"<table width=60% border=1 bordercolor=#ff69b4 bgcolor=#f0ffff cellpadding=2 cellspacing=0>";
echo"<tr><td align=center>";
echo"<font size=2 face='MS Sans Serif'>";
echo"<font size=3 color=red><b><br>¡Ãسһé͹¢éÍÁÙÅÊÔ¹¤éÒãËé¤Ãº¶éǹ !<br><br></b></font>";
echo"</font></td></tr></table><br>";
echo"<input type=\"button\" value=\"Âé͹¡ÅѺ\" onclick=\"history.back();\">";
exit;
}
//----------------------------------------------- ¶éÒÁÕ checkbox źÃÙ»ÀÒ¾ (1) -----------------------------------------------------------------
if ($chkdel=="1")
{
$fileupload_name="";
if (edit_product1($pro_id,$category,$pro_title,$fileupload_name,$pro_unit,$pro_price))
{
echo"<meta http-equiv='refresh' content='2; url=productlist.php'>";
echo"<center><br>";
echo"<table width=60% border=1 bordercolor=#ff69b4 bgcolor=#f0ffff cellpadding=2 cellspacing=0>";
echo"<tr><td align=center>";
echo"<font size=2 face='MS Sans Serif'>";
echo"<font size=3 color=red><br><b>Ãкºä´é·Ó¡ÒÃá¡é䢢éÍÁÙÅÊÔ¹¤éÒ <br>ÃËÑÊ <font size=3 color=blue>[ $ISBN ]</font><br>ã¹°Ò¹¢éÍÁÙÅàÃÕºÃéÍÂáÅéÇ<br><br></b></font>";
echo"</font></td></tr></table>";
}else
echo " ¢éÍÁÙÅÊÔ¹¤éÒ ÃËÑÊ '$pro_id' äÁèÊÒÁÒöá¡éä¢ã¹°Ò¹¢éÍÁÙÅä´é";
} // end if (1)
//---------------------------------------------- ¶éÒäÁèÁÕ¡Òà checkbox źÃÙ»ÀÒ¾ (2)-----------------------------------------------------------
else if($chkdel==0)
{
//--------------- ¶éÒ oldfile äÁèà»ç¹¤èÒÇèÒ§ ¨Ðà¡çºä¿Åìà´ÔÁäÇé (2.1)------------------------------
if($oldfile<>"")
{
$fileupload_name=$oldfile;
//-------------------------------------------------------------------------------------------------------
if (edit_product0($pro_id,$category,$pro_title,$fileupload_name,$pro_unit,$pro_price))
{
echo"<meta http-equiv='refresh' content='2; url=productlist.php'>";
echo"<center><br>";
echo"<table width=60% border=1 bordercolor=#ff69b4 bgcolor=#f0ffff cellpadding=2 cellspacing=0>";
echo"<tr><td align=center>";
echo"<font size=2 face='MS Sans Serif'>";
echo"<font size=3 color=red><br><b>Ãкºä´é·Ó¡ÒÃá¡é䢢éÍÁÙÅÊÔ¹¤éÒ <br>ÃËÑÊ <font size=3 color=blue>[ $pro_id ]</font><br>ã¹°Ò¹¢éÍÁÙÅàÃÕºÃéÍÂáÅéÇ<br><br></b></font>";
echo"</font></td></tr></table>";
} else
echo " ¢éÍÁÙÅÊÔ¹¤éÒ ÃËÑÊ '$pro_id' äÁèÊÒÁÒöá¡éä¢ã¹°Ò¹¢éÍÁÙÅä´é";
//---------------------------------------------------------------------------------------------------
} // end if (2.1)
else //------------- ¶éÒ oldfile à»ç¹¤èÒÇèÒ§ ¨Ð upload ä¿ÅìãËÁè (2.2)---------------------
{
//---------------------------- ¡Òà Upload ä¿ÅìÃÙ»ÀҾŧã¹â¿Åà´ÍÃì ---------------------------
$fileupload=$_FILES['fileupload'] ['tmp_name'];
$fileupload_name=$_FILES['fileupload'] ['name'];
$fileupload_size=$_FILES['fileupload'] ['size'];
$fileupload_type=$_FILES['fileupload'] ['type'];
if($fileupload) {
$array_last=explode(".",$fileupload_name);
$c=count($array_last)-1;
$lastname=strtolower($array_last[$c]);
if ($lastname=="gif" or $lastname=="jpg" or $lastname=="jpeg")
{
copy($fileupload,"images/".$fileupload_name); //copy ÃÙ»ÀҾŧã¹â¿Åà´ÍÃì photo
//-------------------------------------------------------------------------------------------------------
if (edit_product0($pro_id,$category,$pro_title,$fileupload_name,$pro_unit,$pro_price))
{
echo"<meta http-equiv='refresh' content='2; url=productlist.php'>";
echo"<center><br>";
echo"<table width=60% border=1 bordercolor=#ff69b4 bgcolor=#f0ffff cellpadding=2 cellspacing=0>";
echo"<tr><td align=center>";
echo"<font size=2 face='MS Sans Serif'>";
echo"<font size=3 color=red><br><b>Ãкºä´é·Ó¡ÒÃá¡é䢢éÍÁÙÅÊÔ¹¤éÒ <br>ÃËÑÊ <font size=3 color=blue>[ $ISBN ]</font><br>ã¹°Ò¹¢éÍÁÙÅàÃÕºÃéÍÂáÅéÇ<br><br></b></font>";
echo"</font></td></tr></table>";
} else
echo " ¢éÍÁÙÅÊÔ¹¤éÒ ÃËÑÊ '$pro_id' äÁèÊÒÁÒöá¡éä¢ã¹°Ò¹¢éÍÁÙÅä´é";
//---------------------------------------------------------------------------------------------------
}
else
{
echo"<center><br><table width=60% border=1 bordercolor=#ff69b4 bgcolor=#f0ffff cellpadding=2 cellspacing=0><tr><td align=center><font size=2 face='MS Sans Serif'><font size=3 color=red><b><br>ä¿ÅìÃÙ»ÀÒ¾äÁèãªèä¿Åì»ÃÐàÀ· GIF ËÃ×Í JPEG<br>¡Ãسһé͹ä¿ÅìÃÙ»ÀÒ¾ãËÁè<br><br></b></font></font></td></tr></table><br><input type=\"button\" value=\"Âé͹¡ÅѺ\" onclick=\"history.back();\">";
}
}
else
{
echo"<center><br><table width=60% border=1 bordercolor=#ff69b4 bgcolor=#f0ffff cellpadding=2 cellspacing=0><tr><td align=center><font size=2 face='MS Sans Serif'><font size=3 color=red><b><br>¡ÃسÒàÅ×Í¡ä¿ÅìÃÙ»ÀÒ¾<br><br></b></font></font></td></tr></table><br><input type=\"button\" value=\"Âé͹¡ÅѺ\" onclick=\"history.back();\">";
}
} // end if (2.2)
} // end if (2)
} //------------------ ÊÔé¹ÊØ´¡ÒõÃǨÊͺ -----------------------
?>
|
|
|
|
|
Date :
2011-06-17 10:48:34 |
By :
myminthom |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เมื่อจะส่งค่าแก้ไขข้อมูลเดิมรอบที่ 2 ก้อจะ กลายเป็น ว่างเปล่า ทั้งๆที่ทีแรกมีการดึงข้อมูลมาเพื่อให้แก้ไขได้ปกติ
|
|
|
|
|
Date :
2011-06-17 10:51:20 |
By :
myminthom |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คุณลอง print_r ($_POST); ในหน้าแก้ไขดูครับ
แล้วสังเกตุการส่งค่าแต่ละครั้งว่ามันส่งมาหน้าแก้ไขอีกครั้งหรือไม่ ?
เข้าฐานข้อมูลหรือเปล่า ?
ตอนดึงฐานข้อมูลมันได้ค่าออกมาหรือเปล่า ?
|
|
|
|
|
Date :
2011-06-17 13:33:25 |
By :
oxygenyoyo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อ้อ เจอจุดผิดที่แก้ไปแล้วค่ะ ยังไงก้อขอบคุณนะคะ ^^
|
|
|
|
|
Date :
2011-06-17 23:36:44 |
By :
myminthom |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|