|
|
|
รบกวนช่วยดูโค้ดอัพหลดภาพ ลงฐานข้อมูลหน่อยนะ พอดีว่า มันแอดไม่ลง แอดพร้อมกัน 5 ภาพ |
|
|
|
|
|
|
|
รบกวนช่วยดูโค้ดอัพหลดภาพ ลงฐานข้อมูลหน่อยนะ พอดีว่า มันแอดไม่ลง แอดพร้อมกัน 5 ภาพ เราลองทำตามแบบเรียนของเว็บแล้วไม่ได้เลย
อันนี้หน้า from นะค่ะ
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");
}
$db->query($sqlstr,'1');
$lq=mysql_insert_id();
$allowedExtensions = array("jpg","jpeg","gif","png");
$ext=end(explode(".",strtolower($_FILES["pic_wholesale"]["name"])));
if(!in_array($ext,$allowedExtensions)) {
$main->alert($_FILES["pic_wholesale"]["name"].' is invalid file type');
$main->redirect('product_form.php');
exit;
}
else{
move_uploaded_file($_FILES["pic_wholesale"]["tmp_name"],"../images_product/$lq.jpg");
}
$db->query($sqlstr,'1');
$lq=mysql_insert_id();
$allowedExtensions = array("jpg","jpeg","gif","png");
$ext=end(explode(".",strtolower($_FILES["pic1"]["name"])));
if(!in_array($ext,$allowedExtensions)) {
$main->alert($_FILES["pic1"]["name"].' is invalid file type');
$main->redirect('product_form.php');
exit;
}
else{
move_uploaded_file($_FILES["pic1"]["tmp_name"],"../images_product/$lq.jpg");
}
$db->query($sqlstr,'1');
$lq=mysql_insert_id();
$allowedExtensions = array("jpg","jpeg","gif","png");
$ext=end(explode(".",strtolower($_FILES["pic2"]["name"])));
if(!in_array($ext,$allowedExtensions)) {
$main->alert($_FILES["pic2"]["name"].' is invalid file type');
$main->redirect('product_form.php');
exit;
}
else{
move_uploaded_file($_FILES["pic2"]["tmp_name"],"../images_product/$lq.jpg");
}
$db->query($sqlstr,'1');
$lq=mysql_insert_id();
$allowedExtensions = array("jpg","jpeg","gif","png");
$ext=end(explode(".",strtolower($_FILES["pic3"]["name"])));
if(!in_array($ext,$allowedExtensions)) {
$main->alert($_FILES["pic3"]["name"].' is invalid file type');
$main->redirect('product_form.php');
exit;
}
else{
move_uploaded_file($_FILES["pic3"]["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, CakePHP
|
|
|
|
|
|
Date :
2011-06-07 15:28:06 |
By :
badtzyui |
View :
723 |
Reply :
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำไมคุณไม่ทำเป็น Loop ครับ ง่ายกว่าจะเขียน Code สั้นกว่าด้วยครับ
|
|
|
|
|
Date :
2011-06-07 15:36:30 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำยังไงหรอค่ะ
|
|
|
|
|
Date :
2011-06-07 16:13:19 |
By :
badtzyui |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
for($i=1;$i<=$_POST["hdnLine"];$i++)
{
if($_POST["txtCustomerID$i"] != "")
{
$strSQL = "INSERT INTO customer ";
$strSQL .="(CustomerID,Name,Email,CountryCode,Budget,Used) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["txtCustomerID$i"]."','".$_POST["txtName$i"]."', ";
$strSQL .="'".$_POST["txtEmail$i"]."' ";
$strSQL .=",'".$_POST["txtCountryCode$i"]."','".$_POST["txtBudget$i"]."', ";
$strSQL .="'".$_POST["txtUsed$i"]."') ";
$objQuery = mysql_query($strSQL);
}
}
echo "Save Done. Click <a href='phpMySQLListRecord.php'>here</a> to view.";
mysql_close($objConnect);
?>
</body>
</html>
ตัวอย่างการใช้แบบ Loop ครับ
Go to : PHP MySQL Add/Insert Multiple Record
|
|
|
|
|
Date :
2011-06-07 16:17:16 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่ได้จริงๆๆ ม่ายรุจะเอามาใส่ยังไง
|
|
|
|
|
Date :
2011-06-07 19:40:20 |
By :
badtzyui |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คืออยากทราบว่า มันจะใช้ for loop ได้หรอค่ะ เพราะว่า รูป 5 รูปที่ต้องการแอด มานจะต้องแอดลงพร้อมข้อมูล
|
|
|
|
|
Date :
2011-06-07 20:04:18 |
By :
badtzyui |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|