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

Write to text file

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a

<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

P: n/a
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

P: n/a
<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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.