blog problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi, I know this is not a php newsgroup but I have tried posting in alt.php
and various other newsgroups and have recieved a less than warm welcome.  
I'm fairly new to php and ahve written my own blog which doesn't seem to
work.  I know that a lot of you lot know quite a bit about php and I was
wondering if you would be a able to help.  Can anyone see anything worng
with this.  Many thanks in advance!

    $title = $_POST["title"];
    $body = $_POST["body"];
    $counter = file("counter.txt");
    $delete = $counter - $amount;
    $new = $counter + 1;

    unlink("posts/posts $delete .txt", "w");

    $fptr = fopen("posts/posts $counter .txt", "w");
        fwrite($fptr, $title);

    $fptr = fopen("counter.txt", "w");
        fwrite($fptr, $new);

    echo "Site updated";

Re: blog problem

Quoted text here. Click to load it

For starters, what is the problem in your opinion?

Where is $amount defined?

Your unlink statement appears to be deletinga file with a name of
something like "posts 2 .txt" is that either correct or wise?

You need to read the syntax for "unlink".  Why would it have a parameter
that allows you to write to a file you're deleting?

Why don't you do this the sensible way and use a database?  If you've
got PHP, it's likely that you have MySQL.

Hywel     I do not eat quiche /

Re: blog problem

Quoted text here. Click to load it

Right, well i got a friend to help me and I seem to have it sorted except
for two things.  When trying use my php blog it won't work unless I remove
the following lines...

    $delete = $counter - 6;
    $new = $counter + 1;

...both of which are crucial for my blog to work properly.  A message
states that these are unknown operands.
Scond problem is it writes the new file all fine and dandy except it calls
it post'array'.txt when really it should be could post1.txt.

Re: blog problem

King of Red Lions wrote:

Quoted text here. Click to load it

You see, it would have really helped if you'd posted what you actually
wanted your code to do.

    $counter = file("counter.txt");

The file() function doesn't return a string, but an *array* of strings.
This throws off the rest of your code. Try this instead:

    $arr = file("counter.txt");
    $counter = $arr[0];

Toby A Inkster BSc (Hons) ARCS
Contact Me -

Re: blog problem

Quoted text here. Click to load it

Well, it's not HTML, for one. ;-)
Where does $amount come from?
Are those filenames in unlink and fopen? If so why the spaces?
What the hell is it SUPPOSED to do?

p.s. I've never even seen a PHP program before...

Site Timeline