Write to text file

This is a discussion on Write to text file within the PHP Language forums, part of the PHP Programming Forums category; Hello I'm a complete php noob and a non-programmer. I would appreciate any help. I have a form ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-27-2005
jcwmtl@hotmail.com
 
Posts: n/a
Default 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

Reply With Quote
  #2 (permalink)  
Old 05-27-2005
askMe
 
Posts: n/a
Default Re: Write to text file

A popup is a new page. You just need to program the new pages title,
size, scroll, and other elements.

http://www.askblax.com

Reply With Quote
  #3 (permalink)  
Old 05-27-2005
Richard Quick
 
Posts: n/a
Default Re: Write to text file


<jcwmtl@hotmail.com> wrote in message
news:1117165799.646274.319090@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


Reply With Quote
  #4 (permalink)  
Old 05-27-2005
jcwmtl@hotmail.com
 
Posts: n/a
Default Re: Write to text file

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:
> <jcwmtl@hotmail.com> wrote in message
> news:1117165799.646274.319090@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


Reply With Quote
  #5 (permalink)  
Old 05-27-2005
Richard Quick
 
Posts: n/a
Default Re: Write to text file

<jcwmtl@hotmail.com> wrote in message
news:1117193572.836041.28080@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


Reply With Quote
  #6 (permalink)  
Old 05-28-2005
jcwmtl@hotmail.com
 
Posts: n/a
Default Re: Write to text file

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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:57 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0