473,387 Members | 1,892 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.

Write to text file

Hello
I'm a complete php noob and a non-programmer.
I would appreciate any help.
I have a form which takes user input. On submit, the form will run a
php script that will create a new text file using the user input.

I want this text file to popup or open in a new page. The problem is
that when the page opens it still shows the old text file, i need to
hit refresh for it to show the last user input.

the html file (greatly simplified):
<html><head>
<title>Untitled</title>
</head>
<body>
<form action="action.php" method="post">
<p>Title: <input type="text" name="Title" /></p>
<p><input type="submit" /></p>
</form>
</body>
</html>

The php file (simplified as well):
<?php

$spot_code = $_POST['Title'];

// Open the file and erase the contents if any
$fp = fopen("myfile.3dml", "w");

fwrite($fp, "<TITLE NAME=" . '"'. $spot_code .'"'. " />\n");

fclose($fp);

//redirect
header( 'Location: http://localhost/mytest/myfile.html' );

?>

the text file, myfile.3dml is embedded in myfile.html (it requires a
plugin to view - it's a 3D world). When myfile.html is opened it
displays myfile.3dml but it needs to be refreshed to show the current
input.

how can i ensure the current input is displayed.
also, how would i make a popup appear rather than have myfile.html open
in a new page.
thanks

Jul 17 '05 #1
5 3606
A popup is a new page. You just need to program the new pages title,
size, scroll, and other elements.

http://www.askblax.com

Jul 17 '05 #2

<jc****@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hello
I'm a complete php noob and a non-programmer.
I would appreciate any help.
I have a form which takes user input. On submit, the form will run a
php script that will create a new text file using the user input.

I want this text file to popup or open in a new page. The problem is
that when the page opens it still shows the old text file, i need to
hit refresh for it to show the last user input.

To make the page open up a new page you need to put the following code in
the head of your HTML document (e.g. underneath the title).

<meta http-equiv="REFRESH"
content="0;url=http://www.yoursite.com/newpage.html">

To open a pop-up you'll need to use javascript.

--
Richard Quick
http://www.chocolatemagazine.co.uk
Jul 17 '05 #3
Thanks Richard.
I know how to create a popup using js, but i'm uncertain as to how to
combine that with php.

Richard Quick wrote:
<jc****@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hello
I'm a complete php noob and a non-programmer.
I would appreciate any help.
I have a form which takes user input. On submit, the form will run a
php script that will create a new text file using the user input.

I want this text file to popup or open in a new page. The problem is
that when the page opens it still shows the old text file, i need to
hit refresh for it to show the last user input.

To make the page open up a new page you need to put the following code in
the head of your HTML document (e.g. underneath the title).

<meta http-equiv="REFRESH"
content="0;url=http://www.yoursite.com/newpage.html">

To open a pop-up you'll need to use javascript.

--
Richard Quick
http://www.chocolatemagazine.co.uk


Jul 17 '05 #4
<jc****@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Thanks Richard.
I know how to create a popup using js, but i'm uncertain as to how to
combine that with php.


You should just be able to get PHP to generate the URL of the page you want
to appear in the pop up.

eg. if the page you want to display has the url:

www.mysite.com/page.php?query=123

and you have a javascript function called makepopup which takes a url as a
variable

Then you would put the following (or similar) in your html code:

makepopup('<?php echo $urlToVisit; ?>')

--
Richard Quick
http://www.chocolatemagazine.co.uk
Jul 17 '05 #5
Thank you so much Richard.
I put the refresh in the php and my file refreshes properly now.

Hate to trouble you some more, but if i wanted the html file in a frame
rather than a new page...how would i modify the php?

the php (simplified) looks like this now:
<?php
$spot_code = $_POST['Title'];
$fp = fopen("myfile.3dml", "w");
fwrite($fp, "<TITLE NAME=" . '"'. $spot_code .'"'. " />\n");
fclose($fp);
?>
<meta
http-equiv="REFRESH"content="0;url=http://localhost/spotcoder/myfile.html">

the above code takes input from a first html file, writes it to file
myfile.3dml which is embedded in myfile.html.
myfile.html opens in a new page. could i make it open in a frame..ie.
with some target=main attribute?

thanks

Jul 17 '05 #6

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

Similar topics

3
by: John Flynn | last post by:
hi, having problems reading from and writing back to the same file. basically, i want to read lines of text from a file and reverse them and write them back to the same file.. it has to...
1
by: Magix | last post by:
Hi, I have these string data: str_data1, str_data2, str_data3, which capture some value after a routine process A. Then I would like to write (append) these 3 string values into a text file each...
1
by: Jim Heimer | last post by:
Hi, I've been using schema.ini to read an ascii file to a dataset. Would it be possible to write to the ascii file the same way I read from it? In my case, the initial ascii file has two...
9
by: msuk | last post by:
All, I have a well form block of XML that is stored in a C# string type and I just simply want to display it in the browser using Response.Write but when I try this I get the following error: ...
10
by: Mike | last post by:
I have a text file that i need to write multiple lines of data to but one at a time. how can i write more then one line of data to the file? example: i do a search for a file on a server if the...
12
by: Nina | last post by:
Hi there, What is the maximum length that one line can hold in a text file using StreamWriter's Write or WriteLine method? If the string is too long for one line to hold, what will Write or...
4
by: Billy | last post by:
Hi all, I'm building a text file from a database table using the ASP Write Method and would like to position the cursor in a specific column position before writing the fields. As I loop through...
6
Atran
by: Atran | last post by:
Hello: In this article: You will learn to Write or Read A Text File. Let's Begin: First Create a new project (ConsoleApp or WinApp). And Make sure your program uses these namespaces: using...
6
by: globalrev | last post by:
i ahve a program that takes certain textsnippets out of one file and inserts them into another. problem is it jsut overwrites the first riow every time. i want to insert every new piece of...
65
by: Hongyu | last post by:
Dear all: I am trying to write to a file with full directory name and file name specified (./outdir/mytestout.txt where . is the current directory) in C programming language and under Unix, but...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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.