Jump to content

PHP - Inputting and echoing a whole file - using textfields


Guest aceooo2

Recommended Posts

Guest aceooo2

Hi, I am a beginner to PHP,

 

I was wondring: Currently I can append and read the file I have appended.

 

But I want to add an HTML form which inputs a textfield, and then actions it back to the PHP page.

 

Also seondly I want to add instructions to test whether a variable passed from the form is NULL and if not outputs the value of the variable (But dont worry about this too much as I have not looked into it yet)

 

The current code is:-

 


<?php
$File = "ws3.txt";
$Handle = fopen($File, 'a');
$Data = "William Green\n";
fwrite($Handle, $Data);
$Data = "Dow Jones\n";
fwrite($Handle, $Data);
print "Data Added<br><br><br>";
fclose($Handle);
?>

<?php
$myFile = "ws3.txt";
$handle = fopen($myFile, 'r');
while (!feof($handle))
{
$data = fgets($handle, 512);
echo $data;
echo "<br>";
}
fclose($handle);
?>

 

Any ideas?, as when I search this PHP site or any others it only talks about uploading images or

Guest aceooo2

Dont worry, I think I got it:-

 

<?php
$myFile = "ws3.txt";
$handle = fopen($myFile, 'r');
while (!feof($handle))
{
$data = fgets($handle, 512);
echo $data;
echo "<br>\n";
}
fclose($handle);
?>

<html>
<body bgcolor="#FFFFFF" text="#000000">
<form>
Please Type in Your Name <br>
<input type=text name=username><br>
<input type=submit value="Submit Data">
</form>
You Type:
<?php
echo($username);
?>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.