|
 |
|
แก้ไขข้อมูลที่ upload รูปไว้ก่อนแล้ว รูปหาย ผมไม่ค่อยเป็นเรื่อง php อ่ะนะครับ พอดีเว็ปมีปัญหาเรื่องการแก้ไขข้อมูล |
|
 |
|
|
 |
 |
|
ผมไม่ค่อยเป็นเรื่องphpอ่ะนะครับ พอดีเว็ปมีปัญหาเรื่องการแก้ไขข้อมูล
เมื่อเรียกแก้ไขค่าทั้งหมดที่อยู่ใน DB ก็จะถูกเอามาเก็บไว้เป็นปกติอ่ะครับ แต่ว่าค่าของ ภาพ ผมเอามาใส่ใน Hiddenไม่เป็น แล้วอีกอย่าง เวลาแก้ไขหากไม่แก้ไขรูปมันก็จะเป็นค่าว่าง ทำให้อัพข้อมูลทับอันเก่าไปรูปเลยหายครับ
<input type="hidden" name="picture2" value="<?=$picture?>"> สร้างไว้แล้วน่ะครับ ><
ส่วนเรียกข้อมูล/head]
<?
if($mode == "addShow" || $mode == "editShow")
{
$topic = $_REQUEST["topic"];
$password = $_REQUEST["password"];
$detail = $_REQUEST["detail"];
$open = $_REQUEST["open"];
$kind = $_REQUEST["kind"];
$howto = $_REQUEST["howto"];
$typesum = $_REQUEST["typesum"];
$werning = $_REQUEST["werning"];
$price = $_REQUEST["price"];
$address = $_REQUEST["address"];
$tel = $_REQUEST["tel"];
$email = $_REQUEST["email"];
$section = $_REQUEST["section"];
$province = $_REQUEST["province"];
$name = $_REQUEST["name"];
if($mode == "editShow")
{
$id = $_REQUEST["id"];
$password = $_REQUEST["password"];
Connectdb();
if( $_SESSION['username']!="")
{
$sql = "SELECT * FROM well WHERE id = $id" ;
}
else
{
$sql = "SELECT * FROM well WHERE id = $id and password = $password" ;
}
$result = mysql_query($sql);
if ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$topic = $row['topic'];
$password = $row['password'];
$picture= $row['picture'];
$detail = $row['detail'];
$open = $row['open'];
$kind = $row['kind'];
$howto = $row['howto'];
$typesum = $row['typesum'];
$werning = $row['werning'];
$price = $row['price'];
$address = $row['address'];
$tel = $row['tel'];
$email = $row['email'];
$section = $row['section'];
$province = $row['province'];
$name = $row['name'];
}
else
{
?>
[head]ส่วนEdit
<?
}
Closedb();
} else if($mode=="edit")
{
list($day2,$month2,$year2,$time2) = explode("/",date("d/m/Y/His"));
$year2 = $year2 + 543;
$uploaddir = 'images/places/';
$uploadName = $year2.$mont2.$day2.$time2.substr($_FILES['picture']['name'],-4);
$uploadfile = $uploaddir . $uploadName;
$size = $_FILES['picture']['size'];
if($size > 0)
{
if (($_FILES["picture"]["type"] == "image/gif") || ($_FILES["picture"]["type"] == "image/jpeg") || ($_FILES["picture"]["type"] == "image/pjpeg"))
{
if( $size < 250000)
{
move_uploaded_file($_FILES['picture']['tmp_name'], $uploadfile);
$chkInsert = "yes";
}
else
{
echo "<script>alert('ขนาดรูปต้องไม่เกิน 250 k')</script>";
}
}
else
{
echo "<script>alert('รูปต้องเป็น .gif และ .jpg เท่านั้น')</script>";
}
}
else
{
$uploadName = $picture;
$chkInsert = "yes";
}
if($chkInsert == "yes")
{
$id = $_REQUEST["id"];
$topic = $_REQUEST["topic"];
$password = $_REQUEST["password"];
$detail = $_REQUEST["detail"];
$open = $_REQUEST["open"];
$kind = $_REQUEST["kind"];
$howto = $_REQUEST["howto"];
$typesum = $_REQUEST["typesum"];
$werning = $_REQUEST["werning"];
$price = $_REQUEST["price"];
$address = $_REQUEST["address"];
$tel = $_REQUEST["tel"];
$email = $_REQUEST["email"];
$section = $_REQUEST["section"];
$province = $_REQUEST["province"];
$name = $_REQUEST["name"];
list($day,$month,$year,$time) = explode("/",date("d/m/Y/H:i:s"));
$year = $year + 543;
Connectdb();
$sql = "update well set topic = '$topic',password = '$password',detail = '$detail',open = '$open',kind = '$kind',howto = '$howto',typesum = '$typesum',werning = '$werning',price = $price,address = '$address',tel = '$tel',email ='$email',section = '$section',province ='$province',picture ='$uploadName',name ='$name' ,timestamp = '$year-$month-$day,$time' where id = $id";
//echo $sql;
$result = mysql_query($sql);
}
if($result > 0 && $chkInsert == "yes")
{
?>
โปรดช่วยชี้แนะ :(
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2010-06-08 21:14:14 |
By :
Salang |
View :
1973 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หน้าฟอร์มก็ใส่อันนี้ไว้ครับ
<input name="oldpic" type="hidden" value="<?=$array["image"]?>">
หน้าโค๊ด phpสำหรับแก้ไข ก็ใส่อันนี้ครับ
if(trim($_FILES["newpic"]["tmp_name"])!="") {
$images = $_FILES["newpic"]["tmp_name"];
}
else
{ $images = $_POST["oldpic"];///ดึงมาจากหน้าฟอร์ม
$new_images = $images;
}
เอาไปดัดแปลงเอานะครับ
Go to : PHP สร้างฟอร์มสำหรับ Upload รูปภาพลงในฐานข้อมูล MySQL พร้อมกับแบบ Form สำหรับการแก้ไขรูปภาพ
|
 |
 |
 |
 |
Date :
2010-06-09 14:36:42 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|