By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,553 Members | 936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,553 IT Pros & Developers. It's quick & easy.

How to save text field data in a text file with multiple values separated by comma?

P: 9
Below is the field where user enters his/her email address and the AJAX post request is sent to the server and the user sees the message:

[PHP]echo("<div id=\"message\" class=\"success\">Thank you! You have been successfully registered.</div>");[/PHP]
within 1.5 seconds.

[PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Testing Homepage</title>
<link href="main.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" language="javascript">
// Set path to PHP script
var phpscript = 'subscribe.php';
function createRequestObject() {
var req;
// Firefox, Safari, Opera...
req = new XMLHttpRequest();
} else if(window.ActiveXObject) {
// Internet Explorer 5+
req = new ActiveXObject("Microsoft.XMLHTTP");
} else {
// There is an error creating the object,
// just as an old browser is being used.
alert('There was a problem creating the XMLHttpRequest object');
return req;

// Make the XMLHttpRequest object
var http = createRequestObject();
function sendRequestPost(data) {
var emailPat = "^([0-9a-z]+)([0-9a-z._-]+)@([0-9a-z._-]+)\.([0-9a-z]+)";
var vemailid=document.getElementById('email1').value;
var matchArray = vemailid.match(emailPat);
if(document.getElementById('email1').value == '')
alert("'Email Address' field can not be blank.");
else if (matchArray == null)
alert("Your email address seems incorrect. Please try again.");
else {'post', phpscript, true);
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http.setRequestHeader("Connection", "close");
http.onreadystatechange = handleResponsePost;
function handleResponsePost() {
if(http.readyState == 4 && http.status == 200){
var response = http.responseText;
if(response) {
document.getElementById("dt").innerHTML = response;
<div class="subscribe">
<br />
Email Address: <input type="text" name="email1" id="email1" maxlength="36" size="36" />
<input type="button" name="go" value="Register" onclick="sendRequestPost(document.getElementById(' email1').value);" />
<div id="dt"></div>

This is subscribe.php:
$email = $_POST['email1'];
echo("<div id=\"message\" class=\"success\">Thank you! You have been successfully registered.</div>");

Now my question is:
How to save text field data (i.e. the email address entered by the user) in a text file with multiple values separated by comma? Or in other case how to save these values in an Excel CSV file. We do not want these values to be stored in a database but just want a text file to be created on the first entered value and the rest of the values when entered second time or third time should be appended with the separation of comma i.e:,,
and like that.
Can any one help?
Jun 29 '07 #1
Share this Question
Share on Google+
4 Replies

Expert Mod 15k+
P: 16,027
So you want this file on the server?
Jun 30 '07 #2

Expert 100+
P: 1,044
Why on earth would you *not* want this to be in a database?

And BTW, you can do the file alteration very easily through PHP with fopen(), fread(), and fwrite().
Jul 1 '07 #3

P: 9
Hi guys
Thx for replying. Sunday was officially off, therefore I couldn't reply.
Let me tell you the whole story:
Actually we are a software company, and nowadays the workload is huge, and during this huge workload there comes a client who want their website to be developed in 15 days! After negotiation client understood that this is not posible, therefore by mutual undertanding we (client and us) have decided to just build an under construction website (that is a web site with only a single page). But the client insisted that there should be an email field for the visitor to enter his email address and because we are in a hurry we are not building a database, just a text file to be on the server (as 'acoder' i.e. the 'moderator' said). After 1.5 months or so we will start developing their database and the rest of the website and therefore will want those email addresses to be kept in a column and these email addresses will also be used to send an official email to the registered visitors that now the website is no more under construction etc.
Since I am new to the world of PHP, therefore I want to ask about fopen() and fwrite(). Where this function should be written in case of Ajax POST request as already mentioned in by previous message? How will this take the data inserted in text field to the text file with a comma between these addresses?
Jul 2 '07 #4

P: 9
Hey finally resolved. Thx a lot both of you.
Jul 2 '07 #5

Post your reply

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