Please help me out with this

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JohnnyOhhh
Forum Newbie
Posts: 4
Joined: Tue Oct 20, 2009 4:59 pm

Please help me out with this

Post by JohnnyOhhh »

Trust me, I realize I am about to get pwned by you guys for being a new poster on the board already asking for help but I really need it... I cant figure out why this wont work. It seems to be correct, am I missing something?

oh yeah... the point. Im trying to get this simple form to edit the content of these text files so that I can use them with another script.

Code: Select all

<?php
$name = "name.txt";
$file01 = fopen($name, "w+");
if($_POST['name']) fwrite($file01, $_POST['name']);
fclose($name);
 
$price = "price.txt";
$file02 = fopen($price, "w+");
if($_POST['price']) fwrite($file02, $_POST['price']);
fclose($price);
 
$desc = "desc.txt";
$file03 = fopen($desc, "w+");
if($_POST['desc']) fwrite($file03, $_POST['desc']);
fclose($desc);
 
$barcode = "barcode.txt";
$file04 = fopen($barcode, "w+");
if($_POST['barcode']) fwrite($file04, $_POST['barcode']);
fclose($barcode);
?>
 
 
<form action="<?=$PHP_SELF?>" method="post">
  <p>Name:
    <input type="text" name="name"/>
  </p>
<p>Price:
    <input type="text" name="price"/>
  </p>
<p>Description:
    <input type="text" name="desc"/>
  </p>
<p>Barcode #:
    <input type="text" name="barcode"/>
  </p>
  <p>
    <input type="submit"/>
  </p>
</form>
thanks for your help guys this is really bugging me.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Please help me out with this

Post by requinix »

A description of what "wont work" means would be nice.

(Though I can say now, all your fcloses should be using the $fileXX variables and not the file names themselves.)
JohnnyOhhh
Forum Newbie
Posts: 4
Joined: Tue Oct 20, 2009 4:59 pm

Re: Please help me out with this

Post by JohnnyOhhh »

ok, so what is going on is there is no error when it comes to validation, and the txt files are all set to be written, but when I input data and send it to the server, then go in and read the txt files there is still no data meaning it didnt work. Im going to try what you said and see if it works. thank you!

UPDATE: Nope... that wasn't it tasairis

I want it to open the file and completely replace the content, then save it for use with another script. currently I don't know if my changes are simply being lost after I move to the new script.
JohnnyOhhh
Forum Newbie
Posts: 4
Joined: Tue Oct 20, 2009 4:59 pm

Re: Please help me out with this

Post by JohnnyOhhh »

Ok so...
now the server returns "cant open name.txt" which means if it didn't hang up there it would probably do the same thing for the other 4. even before I have anything to post this is what shows up.

Code: Select all

 
<body>
<?php
$name = "name.txt";
$file01 = fopen($name, "w+")or die("can't open name.txt");
if($_POST['name']) fwrite($file01, $_POST['name']);
fclose($file01);
 
$price = "price.txt";
$file02 = fopen($price, "w+")or die("can't open price.txt");
if($_POST['price']) fwrite($file02, $_POST['price']);
fclose($file02);
 
$desc = "desc.txt";
$file03 = fopen($desc, "w+")or die("can't open desc.txt");
if($_POST['desc']) fwrite($file03, $_POST['desc']);
fclose($file03);
 
$barcode = "barcode.txt";
$file04 = fopen($barcode, "w+")or die("can't open barcode.txt");
if($_POST['barcode']) fwrite($file04, $_POST['barcode']);
fclose($file04);
?>
 
 
<form action="<?=$PHP_SELF?>" method="post">
  <p>Name:
    <input type="text" name="name"/>
  </p>
<p>Price:
    <input type="text" name="price"/>
  </p>
<p>Description:
    <input type="text" name="desc"/>
  </p>
<p>Barcode #:
    <input type="text" name="barcode"/>
  </p>
  <p>
    <input type="submit"/>
  </p>
</form>
 
Post Reply