Page 1 of 1
Problems With My Code
Posted: Mon Nov 28, 2005 11:23 am
by Majoraslayer
Well, I'm still new to PHP and my web host has error reporting turned off
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
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.
Re: Problems With My Code
Posted: Mon Nov 28, 2005 11:40 am
by BDKR
Majoraslayer wrote:Well, I'm still new to PHP and my web host has error reporting turned off
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
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?
Posted: Mon Nov 28, 2005 11:58 am
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.