สร้างฟอร์มเก็บแบบ Text File พอเปิดฟอร์มใหม่ ข้อมูลหายแก้ไงครับ

เริ่มโดย pungplai, 01 สิงหาคม 2012, 19:40:07

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

pungplai

สร้างฟอร์มเก็บไฟล์และแสดงได้ตามต้องการ แต่หลังจากปิดไปแล้ว และเปิดฟอร์มขึ้นมาใหม่ข้อมูลใน Text File มันหายไปหมด
เหมือนแบบว่า เปิดใหม่ ฟอร์มมันว่างเลยเท่ากับว่า ไฟล์ว่างไปด้วย จะทำอย่างไรให้มัน ล็อคไฟล์เก็บไว้
ต้อง submit ก่อนเท่านั้นจึงจะเขียนไฟล์ทับได้ ดูตัวอย่างไฟล์ด้านล่าง

<?php
//Get Form
$title$_POST['title'];
$path ="text";
$Ftitle ="test.txt";

$fp1 fopen($path."/".$Ftitle,"w");

$data1 $title;

fwrite($fp1,$data1);
fclose($fp1);

?>


<?php
//Read text
$Rpath "text";
$Rtitle "test.txt";
$Rfile1 fopen($Rpath "/" $Rtitle"r");
fpassthru($Rfile1);

?>


แบบนี้พอเปิดใหม่มันไม่เก็บไฟล์ ต้องแก้ไขอย่างไรครับ
[direct=http://forceproduct.com]หัวน้ำพุ force[/direct] [direct=http://www.sprinklerthailand.com/pumps.php]ปั๊มน้ำ Pumps / ปั๊มสระว่ายน้ำ[/direct] [direct=http://www.sprinklerthailand.com/fountains.php]หัวน้ำพุ Fountains[/direct]

beg

ควรตรวจสอบว่ามีการโพสจากฟอร์ม ค่อยจัดเก็บข้อมูลลงไฟล์ครับ


โค้ดที่แก้ไขแล้ว


<?php
//Get Form

if(isset($_POST['title'])){
$title$_POST['title'];
$path ="text";
$Ftitle ="test.txt";

$fp1 fopen($path."/".$Ftitle,"w");

$data1 $title;

fwrite($fp1,$data1);
fclose($fp1);
}
?>


<?php
//Read text
$Rpath "text";
$Rtitle "test.txt";
$Rfile1 fopen($Rpath "/" $Rtitle"r");
fpassthru($Rfile1);

?>

pungplai

อ้างถึงจาก: beg ใน 01 สิงหาคม 2012, 20:00:43
ควรตรวจสอบว่ามีการโพสจากฟอร์ม ค่อยจัดเก็บข้อมูลลงไฟล์ครับ


โค้ดที่แก้ไขแล้ว


<?php
//Get Form

if(isset($_POST['title'])){
$title$_POST['title'];
$path ="text";
$Ftitle ="test.txt";

$fp1 fopen($path."/".$Ftitle,"w");

$data1 $title;

fwrite($fp1,$data1);
fclose($fp1);
}
?>


<?php
//Read text
$Rpath "text";
$Rtitle "test.txt";
$Rfile1 fopen($Rpath "/" $Rtitle"r");
fpassthru($Rfile1);

?>


+ ให้ 1ครับ ได้แล้ว ขอบคุณครับ  :wanwan019:
[direct=http://forceproduct.com]หัวน้ำพุ force[/direct] [direct=http://www.sprinklerthailand.com/pumps.php]ปั๊มน้ำ Pumps / ปั๊มสระว่ายน้ำ[/direct] [direct=http://www.sprinklerthailand.com/fountains.php]หัวน้ำพุ Fountains[/direct]

kppser

$fp1 = fopen($path."/".$Ftitle,"w");
แวะเข้ามาครับตรงที่เห็นเนี่ยครับมันเปิดแปปเขียนทับไปเลยน่าจะเปิดแบบ a หรือ a+ ไรประมาณนี้ครับสามารถเก็บข้อมูลต่อที่ไฟล์เดิมได้ :-[

pungplai

อ้างถึงจาก: kppser ใน 01 สิงหาคม 2012, 21:40:50
$fp1 = fopen($path."/".$Ftitle,"w");
แวะเข้ามาครับตรงที่เห็นเนี่ยครับมันเปิดแปปเขียนทับไปเลยน่าจะเปิดแบบ a หรือ a+ ไรประมาณนี้ครับสามารถเก็บข้อมูลต่อที่ไฟล์เดิมได้ :-[

+1 ขอบคุณครับ
[direct=http://forceproduct.com]หัวน้ำพุ force[/direct] [direct=http://www.sprinklerthailand.com/pumps.php]ปั๊มน้ำ Pumps / ปั๊มสระว่ายน้ำ[/direct] [direct=http://www.sprinklerthailand.com/fountains.php]หัวน้ำพุ Fountains[/direct]