473,397 Members | 1,985 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,397 software developers and data experts.

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

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<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" />
</head>
<body>
<script type="text/javascript" language="javascript">
// Set path to PHP script
var phpscript = 'subscribe.php';
function createRequestObject() {
var req;
if(window.XMLHttpRequest){
// Firefox, Safari, Opera...
req = new XMLHttpRequest();
req.overrideMimeType('text/xml');
} 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.");
document.getElementById('email1').focus();
}
else if (matchArray == null)
{
alert("Your email address seems incorrect. Please try again.");
document.getElementById('email1').focus();
}
else {
http.open('post', phpscript, true);
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http.setRequestHeader("Connection", "close");
http.onreadystatechange = handleResponsePost;
http.send('email1='+data);
}
}
function handleResponsePost() {
if(http.readyState == 4 && http.status == 200){
var response = http.responseText;
if(response) {
document.getElementById("dt").innerHTML = response;
}
}
}
</script>
<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>
</div>
</body>
[/PHP]</html>


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

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:
abc@abc.com,bbb@bbb.org.uk, ccccccccddd@efghi.com
and like that.
Can any one help?
Jun 29 '07 #1
4 4633
acoder
16,027 Expert Mod 8TB
So you want this file on the server?
Jun 30 '07 #2
kovik
1,044 Expert 1GB
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
sufian
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
sufian
9
Hey finally resolved. Thx a lot both of you.
Jul 2 '07 #5

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

Similar topics

7
by: Dave B | last post by:
Does anyone know of a program that will read a text file and fill in a web form with the contents of that file? We need to get about 3000 records (5 fields to each record) into a database owned by...
2
by: Logical | last post by:
I have a form which houses basic inputs, as well as a few multiple select forms. I need to parse all the 'values' which are in this multiple select form (it gets manipulated dynamically client...
22
by: Ram Laxman | last post by:
Hi all, I have a text file which have data in CSV format. "empno","phonenumber","wardnumber" 12345,2234353,1000202 12326,2243653,1000098 Iam a beginner of C/C++ programming. I don't know how to...
5
by: Michael Hill | last post by:
Hi, folks. I am writing a Javascript program that accepts (x, y) data pairs from a text box and then analyzes that data in various ways. This is my first time using text area boxes; in the past,...
1
by: DCM Fan | last post by:
Access 2K, SP3 on Windows 2K, SP4 All, I have an import spec set up with quoted Identifiers and comma-separated values. The text file is produced by a 3rd-party program of which I have no...
4
by: Dorte | last post by:
Hi, I am using the code below to stream a CSV file with the response object. Dim FileName As String = "Test.csv" With Web.HttpContext.Current.Response ...
14
by: Ilias Lazaridis | last post by:
within a python script, I like to create a collection which I fill with values from an external text-file (user editable). How is this accomplished the easiest way (if possible without the need...
13
by: sonald | last post by:
Hi, Can anybody tell me how to change the text delimiter in FastCSV Parser ? By default the text delimiter is double quotes(") I want to change it to anything else... say a pipe (|).. can anyone...
2
by: sethridge1991 | last post by:
Hi Everyone, I am trying to send a XML file via SFTP staying completely in UNIX. The data in the file will vary everytime I create and send it. This is not a simple address book dump. This...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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,...

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.