473,773 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Posting information from form to text file

7 New Member
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.tx t";
$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(tr im($name));
if(isset($optio n))
$field[$name][]=htmlentities(t rim($option));
else
$field[$name]='nooptions';
$type[$name]=trim($mytype);
}

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

switch($type[$name]) {

case 'title':
print ("<table><tr><t d width=200 align=center><f ont 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($option s 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><textar ea 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\"><o ption></option>\n");
foreach($option s 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 1951
pbmods
5,821 Recognized Expert Expert
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
1584
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 comes up: "The page cannot be displayed" - The browser can't find the file, because it is looking for http://file2.php instead of http://teachercards.org//file2.php Any help would be greatly appreciated. TIA
3
2576
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 to copy values from two INPUT controls that are located within the Form1 section to hidden INPUT controls located in the SignInForm and post the SignInForm form hidden controls values to a different page (e.g login.aspx) Problem is that after...
2
1740
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 to the server and then the user has to pick this file and send it up to the batchupload page. The batchupload page is not one of our page, instead it is another company's page. This is there interface to do batch processing. We have no control...
7
17338
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 to get it to work in Visual Basic. I tried coding it once myself from scratch and then modified a class that I found on a newsgroup (referenced below). Both seem to be doing the same thing and neither works (or rather, they seem to work but the...
1
496
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 urllib an different broweser (what is the difference). my first attempt was out of the docs: Code: import httplib, urllib params = urllib.urlencode({'email' : 'a@a.com',
3
4032
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 selects? thanks...
44
2979
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, I figured we could talk about it here. Since I'm leading off here, I'll state my opinion on the matter. I really don't care one way or the other. I use Google, and for all its faults, does do one thing right: it hides quoted text. So, I just...
6
10569
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). Seperately the posting words fine but when I want to create one multipart message with both then things go wrong. The binary file is converted and of datatype byte() The xml file is just a string.
0
1516
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. however, if i don't want a repeat of information and the system checks to see if the user is already in the database i get an error. it's either i get the error message "The user name you entered is already on file." all the time or if i put "Not...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.