There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Solved: Trying to write to a file.


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
namenotfound's Avatar
Computer Specs
Distinguished Member with 2,106 posts.
 
Join Date: Apr 2005
Location: New York
Experience: I know what I know, I am
13-Feb-2006, 03:38 PM #1
Solved: Trying to write to a file.
I was getting tired of writing stuff in a file I use as a simple blog on my computer and uploading it to the net each time I wanted to add a new entree. So I wanted to see if I could do all this online.

Here's what I have in a file I made called writer.php

PHP Code:
<?php

$entree 
fopen("blog.php" "a");
$date date("l, F jS, Y");
$time date("g:i:s A T");
$stamp $date "<br />" $time;
fwrite($entree,"<hr /> \n");
fwrite($entree,"<strong>$stamp</strong> \n");
fwrite($entree,"<p>$content</p> \n");
fwrite($entree,"<hr /> \n");
fclose($entree);

echo <<<HTML
<p>Write entrees to the blog here.  Date and Time are automatically added for you.  No need to write them in!</p>
<form action='blog.php' method='post' onsubmit="this.target='_blank';return true;">
<textarea cols='70' rows='20'>$content</textarea><br />
<input type='submit' value='Submit Entry To Blog' />
</form>
HTML;

?>
but what outputs in blog.php is this

HTML Code:
<hr /> <strong>Monday, February 13th, 2006<br />2:09:02 PM CST</strong> <p></p> <hr /> 
Where it says <p></p> is supposed to be the what I entered into the textarea. But as you can see it's empty.

Can anyone fix this for me?
__________________
-----------------------------
| 404: Name Not Found |
-----------------------------
PLEASE NOTE: If I happen to help you in a post, or just simply reply to it, doesn't mean I want to be bombarded with PMs. I answer all questions in posts, not in PMs. Thank you, and have a good day.

<?php $h = 'Hello '; $w = 'World'; echo $h.$w; ?>

My Favorite Editors:
Windows: Crimson Editor
Mac: Taco HTML Edit
Linux: gPHPEdit
namenotfound's Avatar
Computer Specs
Distinguished Member with 2,106 posts.
 
Join Date: Apr 2005
Location: New York
Experience: I know what I know, I am
14-Feb-2006, 10:47 AM #2
anyone?
treydx's Avatar
Senior Member with 112 posts.
 
Join Date: Jan 2006
Experience: Intermediate
14-Feb-2006, 11:17 AM #3
And...
$content = [what?]

Why are you posting your form to the page you're writing? That's crazy, just redirect or use a regular anchor. I'm confused by your HTML, is that from a different page that posts to this one?? Is it supposed to post back to itself? If so, you need to test for a form being submitted before you write to blog.php.

If I was doing this, I'd create two pages.
1. addblog.html
This page would have your form and NAMED textarea on it and post to writer.php.
2. writer.php
This page would just read from your textarea and set $content and your timestamp. It would then redirect you to blog.php so it would be completely hidden from anyone adding an entry to your blog.

Right?
namenotfound's Avatar
Computer Specs
Distinguished Member with 2,106 posts.
 
Join Date: Apr 2005
Location: New York
Experience: I know what I know, I am
14-Feb-2006, 11:19 AM #4
Interesting, can you post some sample code so I can take a better look at what you just said?

No one else is going to make entrees, it's bascally a simple blog of events I'm doing. No one is going to comment. The whole file itself will be hidden, only the end result "blog.php" will be public

$content = whatever I write in the textarea.
__________________
-----------------------------
| 404: Name Not Found |
-----------------------------
PLEASE NOTE: If I happen to help you in a post, or just simply reply to it, doesn't mean I want to be bombarded with PMs. I answer all questions in posts, not in PMs. Thank you, and have a good day.

<?php $h = 'Hello '; $w = 'World'; echo $h.$w; ?>

My Favorite Editors:
Windows: Crimson Editor
Mac: Taco HTML Edit
Linux: gPHPEdit

Last edited by namenotfound : 14-Feb-2006 11:31 AM.
treydx's Avatar
Senior Member with 112 posts.
 
Join Date: Jan 2006
Experience: Intermediate
14-Feb-2006, 11:27 AM #5
So when this page runs, your blog has already been appended before you click "submit to blog"? It makes more sense now

so how about
$content = $_POST['content']?
namenotfound's Avatar
Computer Specs
Distinguished Member with 2,106 posts.
 
Join Date: Apr 2005
Location: New York
Experience: I know what I know, I am
14-Feb-2006, 11:35 AM #6
I tried adding that but doesn't seem to be working
treydx's Avatar
Senior Member with 112 posts.
 
Join Date: Jan 2006
Experience: Intermediate
14-Feb-2006, 11:39 AM #7
Sample Code:

addtoblog.html (very simple page)
HTML Code:
<form method="post" action="writer.php"> <textarea id="content" name="content" cols="1" rows="1"></textarea> <input type="submit" /> </form>
then your writer.php page (which does server side processing)
PHP Code:
<?php

$entree 
fopen("blog.php" "a");
$date date("l, F jS, Y");
$time date("g:i:s A T");
$stamp $date "<br />" $time;
$content $_POST['content'];
fwrite($entree,"<hr /> \n");
fwrite($entree,"<strong>$stamp</strong> \n");
fwrite($entree,"<p>$content</p> \n");
fwrite($entree,"<hr /> \n");
fclose($entree);

?>
Done Adding Entry.
<a href="blog.php">Go to blog</a>
Or instead of the anchor you could just redirect. Is that clear(er)?
namenotfound's Avatar
Computer Specs
Distinguished Member with 2,106 posts.
 
Join Date: Apr 2005
Location: New York
Experience: I know what I know, I am
14-Feb-2006, 11:42 AM #8
That's pretty cool, it works

Thanks
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 06:08 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.