|
|
|
รบกวนช่วยดูโค้ดอัพหลดภาพ ลงฐานข้อมูลหน่อยนะ พอดีว่า มันแอดไม่ลง แอดพร้อมกัน 5 ภาพ |
|
|
|
|
|
|
|
รบกวนช่วยดูโค้ดอัพหลดภาพ ลงฐานข้อมูลหน่อยนะ พอดีว่า มันแอดไม่ลง แอดพร้อมกัน 5 ภาพ โดยที่ใน 1 row
ไม่รู้จริงๆว่าจะทำยังไง
อันนี้เป็นโค้ดค่ะ ช่วยดูหน่อย ถ้ารู้ว่าต้องใส่โค้ดยังไงตรงไหน ช่วยบอกหน่อยค่ะ ไม่ได้จริงๆ มันจะไม่ทันแล้วด้วยค่ะ
Code (PHP)
<?php
//include_once 'verify.php';
include_once '../config/config.php';
require_once '../class/dbconnect.php';
require_once '../class/main.php';
$db = new dbconnect();
$main = new main();
$filter=$_GET['filter'];
$pid=$_GET['pid'];
$action=$_GET['action'];
$refpage=$_SERVER['HTTP_REFERER'];
if($action=='del'&&$pid!=''){
$main->confirm('Are you sure you want to delete.', $refpage);
$sqlstr="DELETE FROM product WHERE id_product='$pid'";
$db->query($sqlstr,'1');
unlink("../file/product/$pid.jpg");
unlink("../file/product/$pid_s.jpg");
$main->redirect($refpage);
exit;
}
elseif($action=='edit'&&$pid!=''){
$sqlstr="SELECT * FROM product WHERE id_product='$pid'";
$result=$db->query($sqlstr);
}
elseif($action!='add'){
$main->alert('Wrong format url.');
$main->redirect($refpage);
exit;
}
if($_POST){
$product_id=$_POST['product_id'];
$name=$_POST['name'];
$outof =$_POST['outof'];
$status=$_POST['status'];
$retail=$_POST['retail'];
$detail_retail = $_POST['detail_retail'];
$price_retail = $_POST['price_retail'];
$wholesale=$_POST['wholesale'];
$detail_wholesale = $_POST['detail_wholesale'];
$price_wholesale = $_POST['price_wholesale'];
if(!$name){
$main->alert('Plase input both names.');
$main->redirect($refpage);
exit;
}
if($action=='add'){
if(!$_FILES["pic_retail"]["name"]){
$main->alert('Plase upload file.');
$main->redirect($refpage);
exit;
}
else{
$sqlstr="INSERT INTO product (product_id,name,outof,status,retail,detail_retail,price_retail,wholesale,detail_wholesale,price_wholesale,cat_id) VALUES ('$product_id','$name','$outof','$status','$retail','$detail_retail','$price_retail','$wholesale','$detail_wholesale','$price_wholesale','$filter')";
$db->query($sqlstr,'1');
$lq=mysql_insert_id();
$allowedExtensions = array("jpg","jpeg","gif","png");
$ext=end(explode(".",strtolower($_FILES["pic_retail"]["name"])));
if(!in_array($ext,$allowedExtensions)) {
$main->alert($_FILES["pic_retail"]["name"].' is invalid file type');
$main->redirect('product_form.php');
exit;
}
else{
move_uploaded_file($_FILES["pic_retail"]["tmp_name"],"../images_product/$lq.jpg");
}
}
$sqlstr="UPDATE product SET product_id='$product_id',name='$name',outof='$outof',status='$status',retail='$retail',detail_retail='$detail_retail',price_retail='$price_retail',wholesale='$wholesale',detail_wholesale='$detail_wholesale',price_wholesale='$price_wholesale' WHERE id_product='$pid'";
$db->query($sqlstr,'1');
$main->redirect("product_list.php?filter=$filter");
}
}
?>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
#main , #main a{
margin: auto;
height: auto;
width: 975px;
background-color: #66CCCC;
text-decoration: none;
}
-->
</style>
<div id="main">
<?include_once 'banner.php';?>
<table class="body" width="975" align="center" border="0" cellspacing="10">
<tr>
<td width="200" valign="top">
<?php
include_once 'menu.php';
?>
</td>
<td width="846" valign="top">
<p class="text-title" style="margin-top: 0px; margin-bottom: 0px;"><? if($action=='add') echo 'เพิ่ม'; elseif($action=='edit') echo 'แก้ไข';?>สินค้า</p>
<form enctype="multipart/form-data" name="form_newsevent_form" id="form_newsevent_form" method="post" action="">
<table width="84%" align="center">
<tr align="center" valign="top">
<td colspan="2"><table width="74%">
<tr>
<td width="24%" align="left" valign="top">รหัสสินค้า ::</td>
<td width="76%" align="left" valign="top"><label>
<input type="text" name="product_id" id="product_id" value="<?echo $result[0]['product_id'];?>"/>
</label></td>
</tr>
<tr>
<td align="left" valign="top">ชื่อสินค้า ::</td>
<td align="left" valign="top"><label>
<input name="name" type="text" id="name" value="<?echo $result[0]['name'];?>" />
</label></td>
</tr>
<tr>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
</tr>
</table></td>
</tr>
<tr align="center" valign="top">
<td><table width="4%" bgcolor="#CCCCCC">
<tr>
<td width="39%" align="left" valign="top" bgcolor="#CCCCCC"><label>
<input type="checkbox" name="wholesale" id="wholesale" value="1" <? if($result[0]['wholesale']) echo "checked";?>>
</label>
ขายส่ง</td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#CCCCCC">อัพโหลดภาพ</td>
</tr>
<tr>
<td align="center" valign="top" bgcolor="#CCCCCC"><img src="../images/p1b.jpg" width="170" height="227" /></td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#CCCCCC"><input name="pic_wholesale" type="file" id="pic_wholesale" size="35" /></td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#CCCCCC">รายละเอียด ::</td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#CCCCCC"><textarea name="detail_wholesale" cols="45" rows="14" wrap="soft" id="detail_wholesale" ><?echo $result[0]['detail_wholesale'];?></textarea></td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#CCCCCC">ราคา ::
<input name="price_wholesale" type="text" id="price_wholesale" size="20" value="<?echo $result[0]['price_wholesale'];?>"/>
บาท</td>
</tr>
</table></td>
<td><table width="46%" bgcolor="#CCCCCC">
<tr>
<td width="46%" align="left" valign="top" bgcolor="#CCCCCC"><label>
<input type="checkbox" name="retail" id="retail" value="1" <? if($result[0]['retail']) echo "checked";?> />
</label>
ขายปลีก</td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#CCCCCC">อัพโหลดภาพ</td>
</tr>
<tr>
<td align="center" valign="top" bgcolor="#CCCCCC"><img src="../images/p1b.jpg" alt="" width="170" height="227" /></td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#CCCCCC"><input name="pic_retail" type="file" size="35" id="pic_retail" /></td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#CCCCCC">รายละเอียด ::</td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#CCCCCC"><textarea name="detail_retail" cols="45" rows="14" wrap="soft" id="detail_retail"><?echo $result[0]['detail_retail'];?></textarea></td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#CCCCCC">ราคา ::
<input name="price_retail" type="text" id="price_retail" value="<?echo $result[0]['price_retail'];?>" size="20" /></td>
</tr>
</table></td>
</tr>
<tr align="center" valign="top">
<td colspan="2"><table width="74%">
<tr>
<td align="center" valign="top"><table width="399" align="left">
<tr>
<td>ใส่ภาพอื่นๆ ::</td>
</tr>
</table> </td>
</tr>
<tr>
<td align="center" valign="top"><input name="pic1" type="file" id="pic1" size="35" /></td>
</tr>
<tr>
<td align="center" valign="top"><input name="pic2" type="file" size="35" id="pic2" /></td>
</tr>
<tr>
<td align="center" valign="top"><input name="pic3" type="file" size="35" id="pic3" /></td>
</tr>
<tr>
<td align="center" valign="top"> </td>
</tr>
<tr>
<td align="left" valign="top"><input type="checkbox" name="outof" id="outof" value="1" <? if($result[0]['outof']) echo "checked";?>>
สินค้าหมด</td>
</tr>
<tr>
<td align="left" valign="top"><input type="checkbox" name="status" id="status" value="1" <? if($result[0]['status']) echo "checked";?>>
แสดง/ซ่อน</td>
</tr>
<tr>
<td align="left" valign="top"> </td>
</tr>
<tr>
<td align="left" valign="top"><table width="131" align="center">
<tr>
<td><input type="submit" name="button" id="button" value="บันทึก" />
<input type="reset" name="button2" id="button2" value="ยกเลิก" /></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<? //include_once 'footer.php'; ?>
</div>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2011-06-07 20:35:20 |
By :
badtzyui |
View :
766 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
จากคำสั่งมีคำสั่ง move_uploaded_file แค่อันเดียวครับ ไม่มี Loop ด้วยครับ
|
|
|
|
|
Date :
2011-06-08 06:22:53 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ยังไงอ่ะค่ะ ไม่เข้าใจ
|
|
|
|
|
Date :
2011-06-08 11:12:08 |
By :
badtzyui |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|