Jump to content

Some Help Please...


Luke4123

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>

Link to comment
Share on other sites

  • Replies 100
  • Created
  • Last Reply
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>

Link to comment
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.

Link to comment
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>

Link to comment
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.

Link to comment
Share on other sites

Where do I put that?

Link to comment
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).

Link to comment
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?>

Link to comment
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.

Link to comment
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.

Link to comment
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
Link to comment
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

Link to comment
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.
Link to comment
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.

Link to comment
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

Link to comment
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.

Link to comment
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?

Link to comment
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.

Link to comment
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. :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
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>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...