473,387 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Posting information from form to text file

I am trying to append the results from a form to a text file. My code is supposed to print out the results on one page, and append the results to another page each time data is entered on the form and the submit button is hit. Unfortunately, it is only printing out the message acknowledging the submit button--no data on either form. Here is the code below, please help if you can.

PHP code that reads the form submission:
[PHP]<?php

function WriteToFile ($name, $worth) {
$TheFile = "results.txt";
$Open = fopen ($TheFile, "a");
if ($Open) {
fwrite ($Open, "$name: $worth<br>\n");
fclose ($Open);
$Worked = TRUE;
} else {
$Worked = FALSE;
}
return $Worked;
}

for ($n=0; $n < count ($_POST); $n++){
$line = each($_POST);
$line[key] = $name;
$line[value] = $worth;
print ("$name: $worth<br>\n");
$CallFunction = WriteToFile ($name, $worth);
if ($CallFunction) {
print ("Your submission has been received!<br>\n");
} else {
print ("Your submission was not processed due to a system error!<br>\n");
}
}
?>[/PHP]

PHP code for form:
[PHP]<form action="phpform.php" method=POST>
<?php
$field=array();
$type=array();
$lines = file('test_read.txt');
foreach ($lines as $line) {
list($mytype, $name, $option) = explode("=", $line);
$name = htmlentities(trim($name));
if(isset($option))
$field[$name][]=htmlentities(trim($option));
else
$field[$name]='nooptions';
$type[$name]=trim($mytype);
}

foreach ($field as $name => $options) {

switch($type[$name]) {

case 'title':
print ("<table><tr><td width=200 align=center><font size=+1>$name</font></table><br>\n");
break;

case 'label':
print ("<p>$name<br>\n");
break;

case 'checkbox':
print ("<input type=\"checkbox\" name=\"$name\" id=\"$name\" value=\"true\"><label for=\"$name\">$name</label>\n");
break;

case 'radio_button':
print ("<p>$name<br>\n");
foreach($options as $value)
print ("<input type=\"radio\" name=\"$name\" id=\"$name-$value\" value=\"$value\"><label for=\"$name-$value\">$value</label>\n");
break;

case 'comment_box':
print ("<p><label for=\"$name\">$name</label><br>\n");
print ("<p><textarea id=\"$name\" name=\"$name\" rows=\"4\" cols=\"50\"></textarea>\n");
break;

case 'textbox':
print ("<p><label for=\"$name\">$name: </label><input type=\"text\" id=\"$name\" name=\"$name\">\n");
break;

case 'dropbox':
print ("<p><label for=\"$name\">$name: </label><select name=\"$name\" id=\"$name\"><option></option>\n");
foreach($options as $value)
print ("<option value=\"$value\">$value</option>\n");
print ("</select>");
break;
}
}
print ("<p><input type=submit name=submit value=\"SUBMIT\"></form>\n");
print ("<input type=reset value=\"Reset\">\n");
?>
</form>[/PHP]

Text file that form code reads:
Expand|Select|Wrap|Line Numbers
  1. title = Test Form
  2. label = Choose One of These
  3. checkbox = shoe
  4. checkbox = hair
  5. radio_button = Choose One = 3
  6. radio_button = Choose One = 6
  7. comment_box = Comments
  8. dropbox = Select = 18-29 
  9. dropbox = Select = 30-49 
  10. dropbox = Select = 50-75
  11. textbox = Please type your name
Nov 26 '07 #1
1 1923
pbmods
5,821 Expert 4TB
Heya, HotRod.

Try turning on debug messages. You might be hitting a permissions issue.
Nov 27 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Willoughby Bridge | last post by:
I am trying to post from a form to table using the code below from file2.php and having two problems: 1. The data is not being posted to the table 2. After submit is pressed the following message...
3
by: Itai | last post by:
I have an aspx file named index.aspx which contains two ‘form' sections, one that has the runat=server attribute (e.g From1) and one which is a regular HTML form (e.g SignInForm). I am trying...
2
by: ejs | last post by:
Please read the entire reponse, hopefully this clears up your questions. The data used that needs to go into the batchupload page comes from a server. My problem is that currently I write a file...
7
by: Mark Waser | last post by:
Hi all, I'm trying to post multipart/form-data to a web page but seem to have run into a wall. I'm familiar with RFC 1867 and have done this before (with AOLServer and Tcl) but just can't seem...
1
by: evanpmeth | last post by:
I have tried multiple ways of posting information to a website and have failed. I have seen this problem on other forums can someone explain or point me to information on how POST works through...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
44
by: Bruce Wood | last post by:
This subject has come up several times in this group over the last year. Several people in this group seem to feel strongly about this topic. Rather than derail other threads with this discussion,...
6
by: fnoppie | last post by:
Hi, I am near to desperation as I have a million things to get a solution for my problem. I have to post a multipart message to a url that consists of a xml file and an binary file (pdf)....
0
by: ashes | last post by:
Hi, i created a register form on a website. The information from the form has to go in the customer table in a database in MS Access. the information is going into the table perfectly. ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.