|
|
|
สอบถามผู้รู้ครับ เรื่องการแก้ไขรูป ผมทำตาม PHP Multiple Upload & Multiple Resize to MySQL |
|
|
|
|
|
|
|
ผมทำตาม PHP Multiple Upload & Multiple Resize to MySQL จากเว็ยนี้ครับ แต่ยังงเรื่องการแก้ไขรูปลง mysql ครับต้องบอกก่อนว่าไฟล์รูปกับข้อมูลผมเก็บคนละ table กันครับ ใครพอแนะนำได้บ้างครับ เพราะพอมันแก้แล้ว รู้ก็ยังไม่ update เลย ยังเป็นค่าเดิมอยู่
อันนี้หน้า edit
Code (PHP)
<html>
<head>
<title>แก้ไข</title>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationTextarea.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationTextarea.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form action="editproduct_save.php?id_otop=<?=$_GET["id_otop"];?>" name="frmEdit" method="post">
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("otop");
$strSQL = "SELECT * FROM product WHERE id_otop = '".$_GET["id_otop"]."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if(!$objResult)
{
echo "Not found id_otop=".$_GET["id_otop"];
}
else
{
?>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="13%">ชื่อผลิตภัณฑ์</td>
<td width="87%"><span id="sprytextfield1"><input name="name_otop" type="text" id="name_otop" value="<?=$objResult["name_otop"];?>" size="50" /></span></td>
</tr>
<tr>
<td><span class="tbtopic">ประเภท</span></td>
<td>
<select name="id_type" >
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("otop");
$strSQL1 = "SELECT * FROM type order by id_type";
mysql_query("SET NAMES tis620",$objConnect);
$objQuery = mysql_query($strSQL1) or die ("Error Query [".$strSQL1."]");
?>
<?
while($objResult1 = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult1["id_type"];?>"
<? if ($objResult1["id_type"] == $_GET["id_type"]){
echo " selected='selected'";
}
?>
><?=$objResult1["name_type"];?></option>
<?
}
?>
</select>
<?
mysql_close($objConnect);
?>
</td>
</tr>
<tr>
<td><span class="tbtopic">ผู้ผลิต</span></td>
<td>
<select name="id_producer" >
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("otop");
$strSQL2 = "SELECT * FROM producer order by id_producer";
mysql_query("SET NAMES tis620",$objConnect);
$objQuery = mysql_query($strSQL2) or die ("Error Query [".$strSQL2."]");
?>
<?
while($objResult2 = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["id_producer"];?>"
<? if ($objResult2["id_producer"] == $_GET["id_producer"]){
echo " selected='selected'";
}
?>
><?=$objResult2["name_producer"];?></option>
<?
}
?>
</select>
<?
mysql_close($objConnect);
?>
</td>
</tr>
<tr>
<td><span class="tbtopic">ประธานกลุ่ม</span></td>
<td><span id="sprytextfield2"><input name="id_president" type="text" id="id_president" value="<?=$objResult["id_president"];?>" /></span></td>
</tr>
<tr>
<td><span class="tbtopic">ประวัติความเป็นมา</span></td>
<td><span id="sprytextarea1"><textarea name="his_otop" id="his_otop" cols="45" rows="3" ><?=$objResult["his_otop"];?></textarea></span></td>
</tr>
<tr>
<td><span class="tbtopic">ขั้นตอนการผลิต</span></td>
<td><textarea name="step_otop" id="step_otop" cols="45" rows="3" ><?=$objResult["step_otop"];?></textarea></td>
</tr>
<tr>
<td><span class="tbtopic">จุดเด่น</span></td>
<td><textarea name="point_otop" id="point_otop" cols="45" rows="3" ><?=$objResult["point_otop"];?></textarea></td>
</tr>
<tr>
<td><span class="tbtopic">ปริมาณการผลิต</span></td>
<td><span id="sprytextfield3"><input name="quantity_otop" type="text" id="quantity_otop" value="<?=$objResult["quantity_otop"];?>" /></span></td>
</tr>
<tr>
<td><span class="tbtopic">ราคา</span></td>
<td><span id="sprytextfield4"><label><input name="price_otop" type="text" id="price_otop" value="<?=$objResult["price_otop"];?>" /> </label><span class="textfieldRequiredMsg">ใส่ราคา</span> บาท</span></td>
</tr>
<tr>
<td><span class="tbtopic">สถานที่จำหน่าย</span></td>
<td><span id="sprytextfield5"><input name="location_otop" type="text" id="location_otop" value="<?=$objResult["location_otop"];?>" size="30" /></span></td>
</tr>
<tr>
<td><span class="tbtopic">สั่งซื้อได้ที่</span></td>
<td><span id="sprytextfield6"><input name="place_otop" type="text" id="place_otop" value="<?=$objResult["place_otop"];?>" size="30" /></span></td>
</tr>
<tr>
<td> </td>
<td>
</td>
</tr> <tr>
<td> </td>
<td>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("otop");
$strSQL3 = "SELECT * FROM files where id_otop='".$_GET["id_otop"]."' order by FilesID";
mysql_query("SET NAMES tis620",$objConnect);
$objQuery = mysql_query($strSQL3) or die ("Error Query [".$strSQL3."]");
?>
<?
while($objResult3 = mysql_fetch_array($objQuery))
{
?><img src="MyResize/<?=$objResult3["Thumbnails"];?>" border="0"><br>
<?=$objResult3["FilesID"];?>
<input type="file" name="fileUpload[]" value="<?=$objResult3["FilesName"];?>"><br>
<?
}
?>
</select>
<?
mysql_close($objConnect);
?>
</td>
</tr>
</table>
<input type="submit" name="submit" value="submit">
<?
}
?>
</form>
<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
var sprytextarea1 = new Spry.Widget.ValidationTextarea("sprytextarea1");
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3");
var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4");
var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5");
var sprytextfield6 = new Spry.Widget.ValidationTextField("sprytextfield6");
//-->
</script>
</body>
</html>
ส่วนอันนี้เป็นหน้าที่รับค่ามาครับ
Code (PHP)
<?
//if(empty($fileUpload))
//{
// }
// else
// {
for($i=0;$i<count($_FILES["fileUpload"]["name"]);$i++)
{
if(trim($_FILES["fileUpload"]["tmp_name"][$i]) != "")
{
$images = $_FILES["fileUpload"]["tmp_name"][$i];
$new_images = "Thumbnails_".$_FILES["fileUpload"]["name"][$i];
copy($_FILES["fileUpload"]["tmp_name"][$i],"MyResize/".$_FILES["fileUpload"]["name"][$i]);
$width=100; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=round($width*$size[1]/$size[0]);
$images_orig = ImageCreateFromJPEG($images);
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
ImageJPEG($images_fin,"MyResize/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
echo "Resize Successful.<br>";
//*** Insert Record ***//
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("otop");
$strSQL1 = "UPDATE files SET ";
//$strSQL1.="id_otop = '".$_GET["id_otop"]."' ";
$strSQL1.="Thumbnails = '".$new_images."' ";
$strSQL1.=",FilesName = '".$_FILES["fileUpload"]["name"][$i]."' ";
$strSQL1.="WHERE FilesID = '".$_GET["FilesID"]."' ";
$objQuery = mysql_query($strSQL1);
}
}
?>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("otop");
$strSQL = "UPDATE product SET ";
$strSQL .="name_otop = '".$_POST["name_otop"]."' ";
$strSQL .=",id_type = '".$_POST["id_type"]."' ";
$strSQL .=",id_producer = '".$_POST["id_producer"]."' ";
$strSQL .=",id_president = '".$_POST["id_president"]."' ";
$strSQL .=",his_otop = '".$_POST["his_otop"]."' ";
$strSQL .=",step_otop = '".$_POST["step_otop"]."' ";
$strSQL .=",point_otop = '".$_POST["point_otop"]."' ";
$strSQL .=",quantity_otop = '".$_POST["quantity_otop"]."' ";
$strSQL .=",price_otop = '".$_POST["price_otop"]."' ";
$strSQL .=",location_otop = '".$_POST["location_otop"]."' ";
$strSQL .=",place_otop = '".$_POST["place_otop"]."' ";
$strSQL .="WHERE id_otop = '".$_GET["id_otop"]."' ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
//echo "Save Done.";
echo "<script language=\"javascript\">alert(\"แก้ไขข้อมูลเรียบร้อยแล้ว\");location=\"addproduct.php\";</script>";
}
else
{
echo "Error Save [".$strSQL."]";
}
mysql_close($objConnect);
?>
<? //} ?>
Tag : - - - -
|
|
|
|
|
|
Date :
2009-10-17 15:59:44 |
By :
it_commer |
View :
1119 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|