Page 1 of 1

help me out please

Posted: Sat Jun 10, 2006 12:55 am
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?

Posted: Sat Jun 10, 2006 1:20 am
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.