Jump to content

Early on Help


Anim9or

Recommended Posts

Hi,

I'm pretty new at PHP, as in I started yesterday, and have been following tutorials from ww3schools.com .  Right now I'm up to reading and writing txt files and I keep getting the same error.  This is the code:

 

<?php
$file=fopen("blah.txt","r");
echo $file;
?>

 

Hower I keep getting:

 

Resource id #6

 

When I open the page.

 

I've searched around for people with simlar problems, but they always have trouble when they reach mySQL.

 

Any help would be much obliged.

 

 

Link to comment
https://forums.phpfreaks.com/topic/118302-early-on-help/
Share on other sites

Thanks for the help!

 

However, I ran into a new problem on the way and I thought it might be easier to place here instead of start a new topic.

 

I'm up to fwrite files now and no matter where I get my code from, I get the same errors, basically, I'm using this:

 

$x=$_GET["suggestion"];
$filename = "data.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fwrite($contents, $x);
echo $contents;
fclose($handle);

 

Now it will just write nothing now, however, if I change the "r" to a "w" or any other writing letters, I get this:

 

Warning: fopen(data.txt) [function.fopen]: failed to open stream: Permission denied in /home/a4975390/public_html/default.php on line 11

 

PHP Error Message

 

Warning: fread(): supplied argument is not a valid stream resource in /home/a4975390/public_html/default.php on line 12

 

 

PHP Error Message

 

Warning: fclose(): supplied argument is not a valid stream resource in /home/a4975390/public_html/default.php on line 15

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/118302-early-on-help/#findComment-609346
Share on other sites

Try:

 

<?php
$x = $_GET["suggestion"];
$filename = "data.txt";
$handle = fopen($filename, "ab");
fwrite($handle, $x);
$contents = fread($handle, filesize($filename));
echo $contents;
fclose($handle);
?>

 

I used "ab" in the handle because I assume you want to "append" the suggestion to the rest of the contents?

Link to comment
https://forums.phpfreaks.com/topic/118302-early-on-help/#findComment-609369
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.