Problems With My Code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Majoraslayer
Forum Commoner
Posts: 64
Joined: Thu Jun 30, 2005 11:50 am
Location: In Your Mind...
Contact:

Problems With My Code

Post by Majoraslayer »

Well, I'm still new to PHP and my web host has error reporting turned off :x

So maybe someone who knows PHP a little better can tell me whats wrong with this code, because since all I get is a blank page in the file that I have it in, I'm guessing its stopping the script from running :cry:

Code: Select all

if( $save == "true" )
 {
$newcontent=$_POST['textcontent']; 
$fh=fopen("notepad.txt","w"); 
fwrite($fh,stripslashes($newcontent)); 
fclose($fh);
 }
I've determined that the problem lies within this block of code, because when I comment it out, everything works fine.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Re: Problems With My Code

Post by BDKR »

Majoraslayer wrote:Well, I'm still new to PHP and my web host has error reporting turned off :x

So maybe someone who knows PHP a little better can tell me whats wrong with this code, because since all I get is a blank page in the file that I have it in, I'm guessing its stopping the script from running :cry:

Code: Select all

if( $save == "true" )
 {
$newcontent=$_POST['textcontent']; 
$fh=fopen("notepad.txt","w"); 
fwrite($fh,stripslashes($newcontent)); 
fclose($fh);
 }
I've determined that the problem lies within this block of code, because when I comment it out, everything works fine.
The code itself looks fine. However, by the time you get to fwrite, you are making an assumption that fopen was successful. You need to make sure the function
worked with success. Try this...

Code: Select all

error_reporting(E_ALL);
if( $save == "true" )
     {
     $newcontent=$_POST['textcontent']; 
     $fh=fopen("notepad.txt","w"); 
     if(!$fh)
        { /* fopen failed! */ }
      else
        { fwrite($fh,stripslashes($newcontent));  }
     fclose($fh);
     }
I also put an error reporting line up at the top. It's worth a try right?

Lastly, do you have a test system?
Majoraslayer
Forum Commoner
Posts: 64
Joined: Thu Jun 30, 2005 11:50 am
Location: In Your Mind...
Contact:

Post by Majoraslayer »

I tried your code, and still I have no error report and just a blank page. Yes, its on a PHP enabled server, but the script that the block of code is in is a phpBB administration page I created. When I comment out that block of code it all works fine, but with it in, the left pane of the admin panel is blank. It does the same thing with your code as it does mine, and still no error reporting.
Post Reply