|
|
|
อยากได้ code การเพิ่มรูปภาพลงฐานข้อมูล mysql (ทำไม่ถูก) |
|
|
|
|
|
|
|
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Ecommerce.........</title>
<link rel="stylesheet" type="text/css" href="anylinkmenu[1].css">
<script language="javascript" src="menucontents.js"></script>
<script language="javascript" src="anylinkmenu.js"></script>
<script type="text/javascript">
//anylinkmenu.init("menu_anchors_class") //Pass in the CSS class of anchor links (that contain a sub menu)
anylinkmenu.init("menuanchorclass")
function showpic(obj){
//alert('xxx');
document.getElementById('pic_name').src=obj.value;
}
</script>
<style type="text/css">
<!--
a:visited {
color: #0000FF;
}
a:hover {
color: #FF00FF;
}
body{margin:0;}
.button{background:#AAFFAA;}
.style12 {font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 14; font-weight: bold; }
.style27 {font-family: AngsanaUPC; font-size: 20px; font-weight: bold; }
-->
</style>
</head>
<body <?php include '../image/bg_body.php';?>
<table width="1000" border="0" align="center">
<tr>
<td align="right" bgcolor="#1164C0"><?php include'../code/banner.php';?></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><?php include "../code/manuadmin.php";?></td>
</tr>
<tr>
<td height="207" align="center" valign="top" bgcolor="#FFFFFF">
<form id="form1" name="form1" method="post" action="../code/add_prd_save.php" enctype="multipart/form-data">
<table width="522" border="0" bordercolor="#FFFBF0">
<tr>
<td colspan="2" align="center" bordercolor="#FFFFFF" bgcolor="#E8EED0" class="style27">เพิ่มสินค้า</td>
</tr>
<tr>
<td width="131" align="right" bordercolor="#E4E9E2" bgcolor="#E4E9E2" class="style12"><span class="style27">ชื่อสินค้า</span></td>
<td width="375" align="left" bordercolor="#CCECD7" bgcolor="#FFFBF0"><input name="name_prd" type="text" id="name_prd" /></td>
</tr>
<tr>
<td width="131" align="right" bordercolor="#E4E9E2" bgcolor="#E4E9E2" class="style12"><span class="style27">ประเภทสินค้า</span></td>
<td align="left" bordercolor="#CCECD7" bgcolor="#FFFBF0"><select name="id_type">
<option value="0">--เลือก--</option>
<?php include('../config/connect_db.php');
$SQL="SELECT *FROM typeprd_tb ORDER BY id_type";
$rs=$db->Execute($SQL)or die('ERROR1');
$num=$rs->NumRows();
while(!$rs->EOF){
$result=$rs->fields;
echo $id_type=$result['id_type'];
$name_type=$result['name_type'];
echo "<option value=$id_type>$name_type</option>";
$rs->MoveNext();
}
?></select> </td>
</tr>
<tr>
<td width="131" align="right" bordercolor="#E4E9E2" bgcolor="#E4E9E2" class="style12"><span class="style27">รายละเอียด</span></td>
<td align="left" bordercolor="#CCECD7" bgcolor="#FFFBF0"><textarea name="detail_prd" cols="30" rows="4" wrap="virtual" id="detail_prd"></textarea></td>
</tr>
<tr>
<td width="131" align="right" bordercolor="#E4E9E2" bgcolor="#E4E9E2" class="style12"><span class="style27">ราคา</span></td>
<td align="left" bordercolor="#CCECD7" bgcolor="#FFFBF0"><input name="price" type="text" id="price" /></td>
</tr>
<tr>
<td width="131" align="right" valign="top" bordercolor="#E4E9E2" bgcolor="#E4E9E2" class="style12"><span class="style27">รูปภาพ</span></td>
<td align="left" valign="top" bordercolor="#CCECD7" bgcolor="#FFFBF0">
<img src="<?php if(empty($pic_name)){
echo'../image/edit.gif';
}?>"name="pic_name" width="100" height="100" id="pic_name" border="1" /></td>
</tr>
<tr>
<td width="131" bordercolor="#E4E9E2" bgcolor="#E4E9E2"> </td>
<td align="left" bordercolor="#CCECD7" bgcolor="#FFFBF0"><input name="pic_name" type="file" onchange="return showpic(this)" size="40" maxlength="50" /></td>
</tr>
<tr>
<td colspan="2" align="center" bordercolor="#CCECD7"><input type="submit" name="Submit" value="ตกลง" class="button"/>
<input type="reset" name="Submit2" value="ยกเลิก" class="button"/></td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
</html>
/*ฟอร์มในการรับข้อมูล*/
<?php
session_start();
$name_prd=$_POST['name_prd'];
$id_type=$_POST['id_type'];
$detail_prd=$_POST['detail_prd'];
$price=$_POST['price'];
$pic_name=$_FILES['pic_name']['tmp_name'];
$pic_name_name=$_FILES['pic_name']['name'];
$pic_name_type=$_FILES['pic_name']['type'];
$pic_name_size=$_FILES['pic_name']['size'];
$date=date("mdY");//04122010
$date1=substr($date,0,2);
$date2=substr($date,2,2);
$date3=substr($date,4,4)+543;
$date_save=$date2."".$date1."".$date3;
include('../config/connect_db.php');
$SQL="SELECT MAX(id_prd) As num FROM prd_tb";
$rs=$db->Execute($SQL)or die('ERROR1');
$Result=$rs->fields;
$MaxID=$Result['num'];
$MaxID;
//exit();
if(empty($MaxID)){
$MaxID=1;
}
else{$MaxID=$MaxID+1;}
////////////////////////////////////////หานามสกุลรูปภาพนะครับ/////////////////////////////////////////////
$array_last=explode(".",$pic_name_name);
$c=count($array_last)-1;
$lastname=strtolower($array_last[$c]);
if($lastname=="gif" or $lastname=="jpg" or $lastname=="jpeg"){
copy($pic_name,"../image/Pic_prd/".$pic_name_name);
$SQL1="INSERT INTO prd_tb(id_prd,name_prd,id_type_prd,detail_prd,price_prd,photo_prd,date_save) VALUES ($MaxID,'$name_prd','$id_type','$detail_prd','$price','$pic_name_name','$date_save')";
//echo "ภาพคุณคือ .gif.jpg.jpeg";
}else{
echo"<script>alert('นามสกุลไฟล์ไม่ถูกต้อง');window.location='../code/add_prd.php';</script>";
}
unlink($pic_name);
$rs1=$db->Execute($SQL1)or die('ERROR2');
if($rs1){
echo"<script>alert('บันทึกข้อมูลเรียบร้อย');window.location='../code/add_prd.php';</script>";
}else{
echo"<script>alert('บันทึกข้อมูลไม่สำเร็จ');window.location='../code/add_prd.php';</script>";
}
?>
ลองประยุกต์ดูนะครับ
|
|
|
|
|
Date :
2010-06-06 16:11:08 |
By :
sleepington |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อืมส่งมายาวดีเฟ้ย แต่เติมอีกนิดนะ db เลือก ชนิดเป็น blob เด้อ ถ้าจะเก็บใน db นะ แต่ถ้าจะเก็บเป็น path ก็ ใช้ varchar ก็ได้
|
|
|
|
|
Date :
2010-06-06 18:37:13 |
By :
Manussawin |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อยากได้โค้ด copy รูป ลงฐานข้อมูลค่ะ c#
|
|
|
|
|
Date :
2010-08-20 14:15:56 |
By :
poona |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถ้า c# ผิดห้องแล้วจ้า ห้องนี้ php
|
|
|
|
|
Date :
2010-08-20 14:20:22 |
By :
aknueng |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|