Jump to content
Luke4123

Some Help Please...

Recommended Posts

This is the code that is currently in post.php:

<html><head><style type="text/css">p {font-family: arial; color: red; }</style></head><head><script type="text/javascript">function message(){alert("Thanks for leaving a comment!");}</script></head><body onload="message()"><?php$writeDATA = ";$writeDATA = $_POST['name']. "/n";$writeDATA = $_POST['post']. "/n";?></body></html>

Share this post


Link to post
Share on other sites
This is the code that is currently in post.php:
<html> <head> <style type="text/css"> p {font-family: arial; color: red; } </style> </head>  <head> <script type="text/javascript"> function message() { alert("Thanks for leaving a comment!"); } </script> </head>  <body onload="message()">  <?php $writeDATA = "; $writeDATA = $_POST['name']. "/n"; $writeDATA = $_POST['post']. "/n"; ?>   </body> </html>

Share this post


Link to post
Share on other sites

Well, we got some problems. Maybe I didn't explain well enough.First, you have two sets of head tags. Just combine all that stuff into one.Next, You still have $writeDATA = "; written with one double quote mark. Maybe your editor is making auto changes. Try writing it like this: $writeDATA = ""; Same thing I was trying to get you to do, really. This, BTW, was probably the source of your error.The other "$writeDATA .=" I DIDN'T want you to change. You leave those dots there, because they are what connect the whole thing into one big string.For now, maybe, just make those changes and echo the results. If everything works, try adding the file functions. I'm going to bed now. Good luck, and keep sticking with it.

Share this post


Link to post
Share on other sites

Gosh this can be quite frustrating. :) It still comes up with that error. This is what it looks like now: Is it right?

<html><head><style type="text/css">p {font-family: arial; color: red; }</style></head><head><script type="text/javascript">function message(){alert("Thanks for leaving a comment!");}</script></head><body onload="message()"><?php$writeDATA = ";$writeDATA .= $_POST['name']. "/n";$writeDATA .= $_POST['post']. "/n";?></body></html>

Share this post


Link to post
Share on other sites

You still have only one quotation mark at $writeDATA = ";. It is supposed to be $writeDATA = followed by a " followed by another " and the ;

$writeDATA = "";

Also, you still need to write that string to a file, e.g.

file_put_contents("file.txt", $writeDATA, FILE_APPEND);

By the way, alert boxes are really irritating.

Share this post


Link to post
Share on other sites

Where do I put that?

Share this post


Link to post
Share on other sites

The file_put_contents() bit goes after you've finished concatenating to $writeDATA (or else not all you wanted would get written to the file).

Share this post


Link to post
Share on other sites

If it's easier, you can go ahead and delete the first line of this. Just change the second line as well to get rid of the dot. I'll also put in some markers where you'll want to do the other stuff.

<?php$writeDATA = $_POST['name']. "/n";$writeDATA .= $_POST['post']. "/n";// create your file name here// write your file contents here// echo something to your user here?>

Share this post


Link to post
Share on other sites

For goodness' sake man!

<html><head><style type="text/css">p {font-family: arial; color: red; }</style><script type="text/javascript">function message(){alert("Thanks for leaving a comment!");}</script></head><body onload="message()"><?php$writeDATA = '';$writeDATA .= $_POST['name']. "/n";$writeDATA .= $_POST['post']. "/n";file_put_contents("file.txt", $writeDATA, FILE_APPEND);?></body></html>

Try this one, and please, compare it to your previous code, re read what others have tried to tell you, and understand NOW what they meant.

Share this post


Link to post
Share on other sites

Thanks for that guys. :) I am starting to understand all the Write Data stuff. But I still dont know what to put it in file.txt.

Share this post


Link to post
Share on other sites
But I still dont know what to put it in file.txt.
1. You don't know what to put into the file itself? You're putting $writeDATA into the file.2. You're under the impression that file.txt is some mysterious variable that needs filling? It's not. It's just the file name. Our friend the robot simply supplied the name 'file.txt' as a reasonable possibility to get you started.Look, BR has you copy and pastable. Just do it.biggrin.gif

Share this post


Link to post
Share on other sites

Oh so I dont need to make any file called file.txt? I copy and pasted the code but I still get an error. Fatal error: Call to undefined function: file_put_contents() in C:\Domains\theolsens.com.au\wwwroot\luke\post.php on line 20

Share this post


Link to post
Share on other sites
Oh so I dont need to make any file called file.txt? I copy and pasted the code but I still get an error. Fatal error: Call to undefined function: file_put_contents() in C:\Domains\theolsens.com.au\wwwroot\luke\post.php on line 20
Get a new host. Yours doesn't seem to support PHP5. If I were you, I'd also send them a note saying why I'm leaving though.

Share this post


Link to post
Share on other sites

Okay, take this part out:

file_put_contents("file.txt", $writeDATA, FILE_APPEND);

Replace it with this:

$F = fopen ("file.txt", "a+"); //a+ is shorthand for FILE_APPENDfwrite ($F, $writeDATA);fclose ($F);

We'll talk about handling errors after you get this down.

Share this post


Link to post
Share on other sites

I changed that so it now looks like this:

<html><head><style type="text/css">p {font-family: arial; color: red; }</style><script type="text/javascript">function message(){alert("Thanks for leaving a comment!");}</script></head><body onload="message()"><?php$writeDATA = '';$writeDATA .= $_POST['name']. "/n";$writeDATA .= $_POST['post']. "/n";$F = fopen ("file.txt", "a+"); //a+ is shorthand for FILE_APPENDfwrite ($F, $writeDATA);fclose ($F);?></body></html>

Yet still another error has occured. Warning: fopen(file.txt): failed to open stream: Permission denied in C:\Domains\theolsens.com.au\wwwroot\luke\post.php on line 20Warning: fwrite(): supplied argument is not a valid stream resource in C:\Domains\theolsens.com.au\wwwroot\luke\post.php on line 21Warning: fclose(): supplied argument is not a valid stream resource in C:\Domains\theolsens.com.au\wwwroot\luke\post.php on line 22

Share this post


Link to post
Share on other sites

No, you're good. I tried the script and it works fine. You almost certainly have never set your luke directory with the correct permissions. (you had no reason to before now.) Do you upload stuff through ftp? If so, go up a level in the ftp window so that you can select the luke directory. Somewhere there ought to be a place where you can check off permissions. Right now, it probably looks like everybody can read, but only owner can write. Check it off so everyone can write. You may have to click something else to save the changes. Then try the script again.

Share this post


Link to post
Share on other sites

Oh ok. That is good than. :) Thanks so much for al your help and teachings. Muchly appreciated. Really helped me understand the writeDATA. :)Do you know how I can change my permissions?

Share this post


Link to post
Share on other sites

I thought I explained how.Even if you're connecting to your server through a control panel, there still should be a place where you can select that directory and click on some stuff. It's just dumb for it not to be there, so it's got to be there. Look.Did your folks set up this system? Maybe they know? (Apologies if you don't actually have folks.)Server stuff is NOT like php, where all the code is the same for everyone, so I really don't know what to tell you, except very generally.

Share this post


Link to post
Share on other sites

Yeah my Dad set it all up but I do have access to it. I have looked through some of the settings but cant find anything. I will ask my Dad. I'm sure he will know. :)Thanks again. :)

Share this post


Link to post
Share on other sites

By the way, the + in "a+" means that the file will be created if it doesn't exist.

Share this post


Link to post
Share on other sites

Hey I have asked a few people if it works for them and they all said no.

Share this post


Link to post
Share on other sites

Still no luck. :) Tried searcihg through everything and can't find anything that will help.

Share this post


Link to post
Share on other sites

What does your code look like now? And did you try DD's code with fopen()?

Share this post


Link to post
Share on other sites

This is what the code looks like now:

<html><head><style type="text/css">p {font-family: arial; color: red; }</style><script type="text/javascript">function message(){alert("Thanks for leaving a comment!");}</script></head><body onload="message()"><?php$writeDATA = '';$writeDATA .= $_POST['name']. "/n";$writeDATA .= $_POST['post']. "/n";$F = fopen ("file.txt", "a+"); //a+ is shorthand for FILE_APPENDfwrite ($F, $writeDATA);fclose ($F);?></body></html>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...