|
|
|
อัพโหลดภาพไม่สำเร็จ โค้ดมันไม่ทำงานส่วน //[Add Image] นะคะ พอมันบันทึก Detail มันก็จบ loop เลยคะ |
|
|
|
|
|
|
|
Code (PHP)
<?
if ($_GET['action']=="add"){
?>
<script language="javascript">
function fncCreateElement(){
var mySpan = document.getElementById('mySpan');
var myLine = document.getElementById('hdnLine');
myLine.value++;
// Create input text
var myElement1 = document.createElement('input');
myElement1.setAttribute('type',"text");
myElement1.setAttribute('name',"txtGalleryName"+myLine.value);
myElement1.setAttribute('id',"txt"+myLine.value);
mySpan.appendChild(myElement1);
// Create input file
var myElement2 = document.createElement('input');
myElement2.setAttribute('type',"file");
myElement2.setAttribute('name',"fileUpload"+myLine.value);
myElement2.setAttribute('id',"fil"+myLine.value);
mySpan.appendChild(myElement2);
// Create <br>
var myElement3 = document.createElement('<br>');
myElement3.setAttribute('id',"br"+myLine.value);
mySpan.appendChild(myElement3);
}
function fncDeleteElement(){
var mySpan = document.getElementById('mySpan');
var myLine = document.getElementById('hdnLine');
if(myLine.value > 1 )
{
// Remove input text
var deleteFile = document.getElementById("txt"+myLine.value);
mySpan.removeChild(deleteFile);
// Remove input file
var deleteFile = document.getElementById("fil"+myLine.value);
mySpan.removeChild(deleteFile);
// Remove <br>
var deleteBr = document.getElementById("br"+myLine.value);
mySpan.removeChild(deleteBr);
myLine.value--;
}
}
</script>
<form action="" method="post" name="addnew" target="" enctype="multipart/form-data">
<div id="frame">
<div class="box-1">
<h3>Add New</h3>
<div class="addrecord">
<ul>
<li><div>Item Code</div> : <input name="txtcode" type="text" maxlength="40"></li>
<li><div>Name </div>: <input name="txtname" type="text"></li>
<li><div>INCI Name </div>: <input name="txtinciname" type="text"></li>
<li><div>Appearance</div> : <textarea name="txtapp" cols="5" rows="5"></textarea></li>
<li><div>Benefit</div> : <textarea name="txtbenefit" cols="5" rows="5"></textarea></li>
<li><div>Percent (%) in use</div> : <input name="txtpercent" type="text"></li>
<li><div>Supplier</div> : <input name="txtsupplier" type="text"></li>
<li><div>Source (Manufacturing)</div> : <input name="txtsm" type="text"></li>
<li><div>Source Type</div> : <input name="txtsourcetype" type="text"></li>
<li><div>Resource</div> : <input name="txtresource" type="text"></li>
<li><div>Images</div>: <input type="text" name="txtGalleryName">
<input name="fileUpload" id="fileUpload" type="file">*.jpg Only</li>
</div>
<li><input name="btnCreate" type="button" value="+" onClick="JavaScript:fncCreateElement();">
<input name="btnDelete" type="button" value="-" onClick="JavaScript:fncDeleteElement();"><br><span id="mySpan"></span>
<li><input name="hdnLine" type="hidden" value="1">
<input name="btnSubmit" type="submit" value="Submit">
</form>
<?
//[Add Detail]
if(isset($_POST['txtcode'])!="")
{
$date_today=date("Y-m-d");
$time_today=date("H:i:s");
$objsql="INSERT INTO ingredient_detial(item_code,name,inic_name,appearance,benefit,percent,supplier,source_m,source_type,resouce,date_today,time_today) VALUES";
$objsql .="('".$_POST["txtcode"]."','".$_POST["txtname"]."','".$_POST["txtinciname"]."','".$_POST["txtapp"]."','".$_POST["txtbenefit"]."','".$_POST["txtpercent"]."','".$_POST["txtsupplier"]."','".$_POST["txtsm"]."','".$_POST["txtsourcetype"]."','".$_POST["txtresource"]."','$date_today','$time_today')";
$objquery=mysql_query($objsql) or die (mysql_error());
$ac_id=mysql_insert_id();
echo "ac_id = ".$ac_id."<br>";
echo "SQL : $objsql";
if($objquery)
{
echo"Save Done";
//("location:index.php");
//exit(0);
}else{
echo"Not recorded";
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//[Add Image]
for($i=1;$i<=(int)($_POST["hdnLine"]);$i++)
{
if($_FILES["fileUpload".$i]["name"] != "")
{
if(copy($_FILES["fileUpload".$i]["tmp_name"],"uploads/".$_FILES["fileUpload".$i]["name"],$ac_id))
{
$sqlimg="INSERT INTO ingredient_img(ac_id,galleryName,images,date_today,time_today)";
$sqlimg.="VALUES('$ac_id','".$_POST["txtGalleryName".$i]."','".$_FILES["fileUpload".$i]["name"]."','$date_today','$time_today')";
$result=mysql_query($sqlimg)or die(mysql_error());
echo $sqlimg;
echo "Copy/Upload ".$_FILES["fileUpload".$i]["name"]." completed.<br>";
}
}
}
echo "<br><a href='php_multiple_upload6.php'>View file</a>";
}//if
}//Add
mysql_close();
?>
Tag : PHP, MySQL
|
ประวัติการแก้ไข 2015-03-16 09:50:14
|
|
|
|
|
Date :
2015-03-13 14:01:31 |
By :
nottpoo |
View :
710 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ยังแก้ไม่ได้เลยนะคะ Please !!!!!
|
|
|
|
|
Date :
2015-03-16 08:27:44 |
By :
nottpoo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($_GET['action']=="add") ไม่มีการรับค่าจากเพจอื่นคะ
ใช่ค่ะ มัน Save Detail ทีแรกโค้ดอัพโหลดไฟล์ ไม่ทำงาน แต่ตอนนี้แก้ได้แล้วคะ เปลี่ยนแนวโค้ดไปเลยอะคะ
|
|
|
|
|
Date :
2015-03-16 16:30:27 |
By :
nottpoo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|