|
 |
|
สอบถามเกี่ยวกับการเก็บ session ค่าเดิม ของ textarea หน่อยครับ |
|
 |
|
|
 |
 |
|
คือผมต้องการให้เมื่อ ทำการกด ยืนยัน เเล้วมีการพบ error ก็ให้เก็บ session ค่าเดิมไว้ ซึ่งตัวอื่นสามารถเก็บค่าเดิมไว้ได้ทั้งหมด เหลือเเค่ในส่วนของ textarea ที่ไม่มีการเก็บค่าเดิมไว้ เเนะนำเพิ่มเติมด้วยครับ
code หน้า Add_Product
Code (PHP)
<tr>
<td><div align="right">รายละเอียดสินค้า</div></td>
<td>
<textarea name="pro_description" id="pro_description" value="<?php echo $_SESSION['pro_description']; ?>" cols="31" rows="5" wrap="virtual"></textarea>
</td>
</tr>
code หน้า check_add_product
Code (PHP)
$pro_description = $_SESSION['pro_description'];
$_SESSION['pro_description'] = $_POST['pro_description'];
// อัพโหลดภาพ
$img = pathinfo(basename($_FILES['pro_image']['name']), PATHINFO_EXTENSION); //ให้ทำการดึงนามสกุลที่มาจากfileที่ผู้ใช้uploadเข้ามา เก็บไว้ใน img
$new_imgage_name = 'img_' . uniqid() . "." . $img; // ชื่อใหม่ของรูป ขึ้นต้นด้วย img_ และใช้ฟังก์ชันuniqid() เพื่อทำการสุ่มชื่อไฟล์ใหม่เพื่อไม่ให้ชื่อซ้ำ ต่อด้วย . เเละตามด้วยนามสกุล
$image_path = "../../image/"; //กำหนดที่อยู่ว่าต้องการให้รูปภาพที่อัพโหลดมาอยู่ในไหน
$upload_path = $image_path . $new_imgage_name; //จะได้ว่า image/ตามด้วยชื่อfileใหม่
//เริ่มupload
$success = move_uploaded_file($_FILES['pro_image']['tmp_name'], $upload_path); //จะประกอบไปด้วยชื่อกล่องที่อัพ เเละชื่อtmpไฟล์ในระบบ คือจะมีย้ายจาก tem_name ไปใส่ไว้ใน upload_path
if ($success == FALSE) {
echo "<script>alert('ไม่สามารถ upload รูปภาพได้');window.location='Add_Product.php';</script>";
exit(); // ออกจากการทำงานทันที
}
// เพิ่มชื่อรูปภาพใหม่เข้าไปในdatabase
$pro_image = $new_imgage_name; // เอาชื่อรูปภาพใหม่เข้ามาไว้ใน $emp_image
$add_pro = "INSERT INTO product (pro_name,cate_id,pro_description,pro_price,pro_stock,pro_image,pro_size,pro_thickness,pro_length,pro_unit)"
. "VALUES ('$pro_name','$cate_id','$pro_description','$tex2','$pro_stock','$pro_image','$pro_size','$pro_thickness','$pro_length','$pro_unit')";
$resule = mysqli_query($con, $add_pro);
echo "<script>alert('บันทึกข้อมูลเรียบร้อยแล้ว');window.location='Manage_Product.php?cate_id=" . $cate_id . "';</script>";
Tag : PHP, HTML5, JavaScript, Ajax, jQuery

|
|
 |
 |
 |
 |
Date :
2019-04-04 15:52:42 |
By :
staff39 |
View :
877 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 00
|