help me out please

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
tinny
Forum Newbie
Posts: 3
Joined: Sat Jun 10, 2006 12:48 am

help me out please

Post by tinny »

ok. This is what I'm (hopelessly) trying to do.

Diagram: http://i26.photobucket.com/albums/c135/ ... iagram.gif

This is what I have so far:

Page 1 - index.php

PHP Code:

Code: Select all

<?php

$myFile = "file1.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo $theData;

?>

<html>
<body>

<form action="insert.php" method="post">
First Name: <input type="text" name="first">
<br>
Enter Sentence: <input name="second" type="text" value="" size="50" maxlength="50" />
<br/>
<input type="Submit" value="Enter">
</form>

</body>
</html>
Page 2 - insert.php

PHP Code:

Code: Select all

<?php
$first - $_POST['first'];
$second = $_POST['second'];
?>

<html>
<body>

<?

$ffile = "file1.txt";
$fh = fopen($ffile, 'w');

fwrite($fh, $count);
fwrite($fh, "\n");
fwrite($fh,$first);
fwrite($fh,$second);

fclose($fh);

$myFile = "file.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh,1);
fclose($fh);
if ($theData == 0){
    
$count=1;
$ffile = "file.txt";
$fh = fopen($ffile, 'w');

fwrite($fh, $count);
fwrite($fh, "\n");
fwrite($fh,$first);
fwrite($fh,$second);

fclose($fh);


}
else{
$ffile = "file.txt";
$fh = fopen($ffile, 'a');

fwrite($fh, $count);
fwrite($fh, "\n");
fwrite($fh,$first);
fwrite($fh,$second);

fclose($fh);

    
}

$myFile = "file.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);


?>

<br><hr>
<? echo $theData?>
<hr>

<form action="index.php">
<input type="Submit" title="back">
</form>

</body>
</html>

And then I have 2 text files.
file.txt

and

file1.txt


Can you help me out please?
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

Can you elaborate on exactly what you're trying to do and what the script is / is not doing at this point?

I can see your logic in the diagram, but what is the second script 'insert.php' doing? You have 5 calls to fopen() there, and it looks like you're trying to swap data around between files? What's the point? At this rate, you may as well be using an RMDBS like MySQL to store and retrieve data.
Post Reply