Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
hi!
i am still pretty new to php but i managed to write a simple html form page that allows someone to key in his name and then click the submit button. Once the form is submitted, i have a php file to write the name to a text file. I've another form that reads the name from the file and prints it to the browser screen. The funny thing here is that when it prints to the screen, I get sort of an extra line below the name printed. For example in the html form page, I key in the name John and click the submit button. When I call the readform.php, i should see the output as Name: John but my output is showing as:
Name: John
Name:
There is an extra name: as shown above. Maybe you guys can help me solve this problem. I have included all the files and the code in this post below.
HTML Form - form.htmCode: Select all
<form name="form1" method="post" action="/Dennis/phptest/submitform.php">
<table width="100%" border="0">
<tr>
<th width="5%" scope="row"><div align="left"><label>Name:</label></div></th>
<th width="95%" scope="row"><div align="left">
<input type="text" name="name">
</div></th>
</tr>
</table>
<p>
<label></label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="Submit">
</label>
</p>
</form>Code: Select all
<?php
$filename = "form.txt";
$myFile = fopen($filename, "w");
fputs($myFile, $_POST['name'] . "\n");
fclose($myFile);
?>Code: Select all
<?php
$filename = "form.txt";
$myFile = fopen($filename, "r");
while (!feof($myFile))
{
$myLine = fgets($myFile, 255);
print("Name: " . "$myLine<br/>");
}
fclose($myFile);
?>feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]