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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • 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.