Schlo_50 Posted August 15, 2007 Share Posted August 15, 2007 Ok then, whats wrong? I have a script which updates a .txt file which used to work fine on my old windows server but now i have upgraded to a linux server it won't work. Please help! Error: "Notice: Undefined variable: save_file in /home/fhlinux165/s/swfrotaryclub.co.uk/user/htdocs/edityear.php on line 19" Script: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <style type="text/css"> <!-- body { background-color: #6191c2; } --> </style></head> <body> <span class="rotary"> <?php $loadcontent = "caldate.txt"; if($save_file) { $savecontent = ($savecontent); $fp = @fopen($loadcontent, "w"); if ($fp) { fwrite($fp, $savecontent); fclose($fp); } } $fp = @fopen($loadcontent, "r"); $loadcontent = fread($fp, filesize($loadcontent)); $loadcontent = htmlspecialchars($loadcontent); fclose($fp); ?> </span><br /> <br /> <form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="savecontent" id="savecontent"> <div align="left"> <p class="rotary">Change Year </p> <p class="rotary"> <textarea name="savecontent" cols="25" rows="1"><?=$loadcontent?> </textarea> <br /> <input type="submit" name="save_file" value="Save" /> </p> </div> </form> </body> </html> Please help, im at my wits end! lol Thanks Quote Link to comment https://forums.phpfreaks.com/topic/65053-solved-update-script/ Share on other sites More sharing options...
gurroa Posted August 15, 2007 Share Posted August 15, 2007 Your linux php configuration has registry_globals set to false. $save_file is stored in associative array $_POST['save_file'] instead of being global. See http://www.php.net/register_globals. Quote Link to comment https://forums.phpfreaks.com/topic/65053-solved-update-script/#findComment-324615 Share on other sites More sharing options...
Schlo_50 Posted August 15, 2007 Author Share Posted August 15, 2007 I now have the following but get the error: "Notice: Undefined variable: savecontent in /home/fhlinux165/s/swfro/user/htdocs/edityear.php" <?php $loadcontent = "caldate.txt"; if (isset($_POST['save_file'])) { $savecontent = ($savecontent); $fp = @fopen($loadcontent, "w"); if ($fp) { fwrite($fp, $savecontent); fclose($fp); } } $fp = @fopen($loadcontent, "r"); $loadcontent = fread($fp, filesize($loadcontent)); $loadcontent = htmlspecialchars($loadcontent); fclose($fp); ?> </span><br /> <br /> <form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="savecontent" id="savecontent"> <div align="left"> <p class="rotary">Change Year </p> <p class="rotary"> <textarea name="savecontent" cols="25" rows="1"><?=$loadcontent?> </textarea> <br /> <input type="submit" name="save_file" value="Save" /> </p> </div> </form> Quote Link to comment https://forums.phpfreaks.com/topic/65053-solved-update-script/#findComment-324624 Share on other sites More sharing options...
MadTechie Posted August 15, 2007 Share Posted August 15, 2007 $savecontent has NOT been set thus you can't set it to itself!!? i see no use for that line! Quote Link to comment https://forums.phpfreaks.com/topic/65053-solved-update-script/#findComment-324627 Share on other sites More sharing options...
gurroa Posted August 15, 2007 Share Posted August 15, 2007 I now have the following but get the error: "Notice: Undefined variable: savecontent in /home/fhlinux165/s/swfro/user/htdocs/edityear.php" Yes it is the same as with $save_file variable. Read that manual page http://www.php.net/register_globals. Quote Link to comment https://forums.phpfreaks.com/topic/65053-solved-update-script/#findComment-324636 Share on other sites More sharing options...
MadTechie Posted August 15, 2007 Share Posted August 15, 2007 personally i would keep register_globals off Quote Link to comment https://forums.phpfreaks.com/topic/65053-solved-update-script/#findComment-324640 Share on other sites More sharing options...
Schlo_50 Posted August 15, 2007 Author Share Posted August 15, 2007 Would turning them off trick the linux server to run the same way in which the windows one used to? I've looked at the manual briefly although i haven't got time to read it all at the moment and take it in. From what i gathered i need to change the script to this: <?php $loadcontent = "caldate.txt"; if (isset($_POST['save_file'])) { $savecontent = (isset($_POST['savecontent'])); $fp = @fopen($loadcontent, "w"); if ($fp) { fwrite($fp, $savecontent); fclose($fp); } } $fp = @fopen($loadcontent, "r"); $loadcontent = fread($fp, filesize($loadcontent)); $loadcontent = htmlspecialchars($loadcontent); fclose($fp); ?> But the code doesn't save the details entered into the text area, instead it saves the number '1'. I guess this is because the text field it is meant to record is set to display 1 line? Quote Link to comment https://forums.phpfreaks.com/topic/65053-solved-update-script/#findComment-324642 Share on other sites More sharing options...
MadTechie Posted August 15, 2007 Share Posted August 15, 2007 $savecontent = (isset($_POST['savecontent'])); change to $savecontent = (isset($_POST['savecontent']))?$_POST['savecontent']:""; Quote Link to comment https://forums.phpfreaks.com/topic/65053-solved-update-script/#findComment-324649 Share on other sites More sharing options...
Schlo_50 Posted August 15, 2007 Author Share Posted August 15, 2007 Thanks very much, works a treat! Quote Link to comment https://forums.phpfreaks.com/topic/65053-solved-update-script/#findComment-324667 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.