473,729 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Newbe php help

I have an HTML form with Firstname, lastname, address

I want to save the firstname, lastname and address appended to a file in say
results.txt, in the below format 1 entry per line...

MyFirstname,MyL astname,MyAddre ss

I know this is probebly easy, can someone help me with a code snippit that
does this?

thanks.

Jul 17 '05 #1
4 1937
I noticed that Message-ID: <vn************ @news.supernews .com> from
eboogyman contained the following:
I want to save the firstname, lastname and address appended to a file in say
results.txt, in the below format 1 entry per line...

MyFirstname,My Lastname,MyAddr ess

I know this is probebly easy, can someone help me with a code snippit that
does this?


I think most people would recommend that you use a database for this.
--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #2
Geoff Berrow wrote:
I noticed that Message-ID: <vn************ @news.supernews .com> from
eboogyman contained the following:

I want to save the firstname, lastname and address appended to a file in say
results.txt , in the below format 1 entry per line...

MyFirstname,M yLastname,MyAdd ress

I know this is probebly easy, can someone help me with a code snippit that
does this?

I think most people would recommend that you use a database for this.


I think that most people would recommande that you use a thermonuclear
balistic weapon to kill a fly.

<op>
If you only have this to store, no relation to other data, and not too
much lines to store, the text file is a perfectly valid solution, and
probably fastest espacially in share hosting environnement.
</op>

Bruno

Jul 17 '05 #3
eboogyman wrote:
I have an HTML form with Firstname, lastname, address

I want to save the firstname, lastname and address appended to a file in say
results.txt, in the below format 1 entry per line...

MyFirstname,MyL astname,MyAddre ss

I know this is probebly easy, can someone help me with a code snippit that
does this?


You'll learn nothing by just copying some code you don't understand.

A few tips :

The form should call a php script in it's 'action' attribute, and the
'GET' or 'POST' method (prefer POST).

In the php script that's called, you can retrieve the 'firstname',
'lastname' and 'address' inputs values in the $_GET or $_POST array :
eg : $firstname = $_POST['firstname']

But you should first check that this value is set with isset() :
if (isset($_POST['firstname']) {
$firstname = $_POST['firstname'];
}
else {
// handle the error
}

You know have to append this to the file. This implies opening the file
in append mode, writing to the file, and closing the file. fopen(),
fwrite() and fclose() are your friends :

http://fr2.php.net/manual/en/function.fopen.php
http://fr2.php.net/manual/en/function.fwrite.php
http://fr2.php.net/manual/en/function.fclose.php

typically, it would do something like :

$file = @fopen('path/to/filename.ext', 'a');
if ($file == false) {
// could not open the file, so handle the error
}
else {
$buffer = "what you have to write\n";
$written = fwrite($file, $buffer);
fclose($file);

// check everything is ok
if ($written != strlen($buffer) ) {
// oops, there was a problem
}
}

To write the three informations on a single line, the simplest thing to
do is to concat them. Now dont forget that you may want to retrieve the
info, and know how to split the line into parts. The usual way is to
insert a separator before the fields. It's best to use a character (or
string) that has very few chances to be in a name or adress. Something
like a pipe ('|'), or a combination of unusual characterd (like '%%%')
should do it.

Now a last few things that might be useful to know:
- with something based on the above code, you won't check if there are
doubles in the persons list
- if you've got a problem when writing the file, it will be somewhat
messed up. It might be useful to backup the file before writing to it.
- the process (here the web server running PHP) must have write access
to the file
- if you don't want every script kiddie and its sister to do anything to
your file, you'd better protect it (this is usually done by some web
server conf file - usually named '.htaccess' if the server is Apache).

With all this and the PHP manual, there is no reason you couldn't write
the code by yourself !-)

HTH
Bruno

Jul 17 '05 #4
Nice explaination, Bruno. Very helpful.

Thanks from another newbie.

Paul
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1658
by: Sebastien GIRAUD | last post by:
Hello, First let say that am french and that i'll try to write the best english i can... I'm a python newbe and have the following problem : I try to create 2 threads in a server program and they seems to block each other. I use something like this : start thread waiting for connexion with : server.threadserver = threading.Thread(target = self.__startserver) then do while 1 : socket, host = accept(...) then start a new thread for each new...
1
1783
by: Ron | last post by:
Is this built into any of the python versions? Need it! Using 2.3.5 and doesn't seem to have it.Newbe needs help!email ron@nac.net Thanks Ron
7
1888
by: Jean Pierre Daviau | last post by:
Hi, <script language="javascript" type="text/javascript"> if(navigator.appName.indexOf("Netscape") != -1){ document.writeln('<link rel="stylesheet" href="~styles/aquarelle_ns.css" type="text/css" media="screen" title="base" />'); }else{ document.write('<link rel="stylesheet" href="~styles/aquarelle.css" type="text/css" media="screen" title="base" />'); }
2
3614
by: Arben Qarkaxhija | last post by:
Hello all, I'm new to AS400 and we have a problem here with a sql-procedure, that is running OK over the Client Access Navigator, but over the 5250 emulator hanging with an error "pointer for the given position not set" (anything like that I think, I have the error in german and here I mean, I have just translated it, but not sure, if the error is shown in english in that way!). Here a peace of code:
9
6688
by: Yaro | last post by:
Hello DB2/NT 8.1.3 Sorry for stupid questions. I am newbe in DB2. 1. How can I read *.sql script (with table and function definitions) into a database? Tool, command... 2. In Project Center I created funcion CREATE FUNCTION DB2ADMIN.xxx( )
1
2022
by: Jim | last post by:
I have created a windows form that contains several tab pages which contain a panels. On a tab page I am trying to dynamically create a series of buttons in that pages panel. I am failing because I can not find the proper way to point to the specific tab page and its panel when creating the buttons. I also need to dynamically change the background color property of each button as it is clicked.
2
2538
by: ken | last post by:
Hello everyone, I'm new to visual VB and I am trying to setup communications using the Function ReceiveSerialData() As String example found in the help section of Microsoft Visual Basic 2005 Express Edition. Sample Code: Function ReceiveSerialData() As String ' Receive strings from a serial port. Dim returnStr As String = ""
17
2716
by: Eric_Dexter | last post by:
def simplecsdtoorc(filename): file = open(filename,"r") alllines = file.read_until("</CsInstruments>") pattern1 = re.compile("</") orcfilename = filename + "orc" for line in alllines: if not pattern1 print >>orcfilename, line I am pretty sure my code isn't close to what I want. I need to be able
1
1196
by: stan | last post by:
I am a complete newbe to python and only got here because I am trying to set up iTunes in game Second Life. Have followed all instructions but keep getting an error reading from my XP Pro OS as follows File "C:\Python24\2L file for iTunes", line 4, in -toplevel- import win32com.client ImportError: No module named win32com.client can someone pls point me in the right direction here as I am trying to urgently fix the file for someones...
0
8761
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
9281
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
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
8148
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
6722
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
6022
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
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.