drfate Posted July 14, 2006 Share Posted July 14, 2006 Hi all, being a user at webfreaks for the last 2 years, their hard drive crashed a few weeks ago and now my simple PHP text editor will not work, I know they have done something on their end because it worked for the last two years. Here is the code that once worked:It basically showed a list of text which I could edit online, nothing special but nice and quick, anyone know why this won't work anymore? The error I'm getting is:Notice: Undefined variable: submit in /home2/impulse/public_html/admin/edit.php on line 3Notice: Undefined variable: data in /home2/impulse/public_html/admin/edit.php on line 11However, I never use to get this error until the server fiddled with something :( I'm at my wits end, any help would be GREATLY appreciated.FILENAME: edit.php<?php if ($submit) { $fp = fopen("data.txt", "w"); fwrite($fp, stripslashes($newdata)); fclose($fp); } $fp = fopen("data.txt", "r"); while (!feof($fp)) { $data .= fgets($fp, 4096); } fclose($fp); ?><html><head><title>simple text editor</title></head><?php $filemod = filemtime('data.txt'); $filemodtime = date("F j Y h:i:s A", $filemod); echo "<center>This File was last updated $filemodtime</center>";?></font><CENTER><form action="<? print $PHP_SELF; ?>" method="post"> <textarea name="newdata" rows="26" cols="40"> <? print $data; ?> </textarea><br><input type="submit" name="submit" value="Submit"></form> Quote Link to comment https://forums.phpfreaks.com/topic/14562-php-code-simple-online-text-editor-that-now-doesnt-work/ Share on other sites More sharing options...
toplay Posted July 14, 2006 Share Posted July 14, 2006 These are notices and not errors per say. However, they usually indicate serious problems that should be addressed.If register_globals are set in the php.ini file, then you can use $submit because PHP will automatically create it for you (assuming that's the name specified in your HTML form). It's best to keep register_globals off for security reasons and program accordingly. This means using $_GET or $_POST depending on your forms method (i.e. $submit = $_GET['submit']).The $submit notice is saying that variable is not defined prior to its use on line 3. So, this can be ignored if register_globals is on since PHP will create and populate it with a value.For the second notice, you should always initialize a variable before using the period concatenation character. Example:$data = ''; // Initialize$fp = fopen("data.txt", "r");while (!feof($fp)) {$data .= fgets($fp, 4096); // initialize before using .=}fclose($fp);Take a look at error_reporting() and display_errors php.ini settings for more info on how to stop notices. Quote Link to comment https://forums.phpfreaks.com/topic/14562-php-code-simple-online-text-editor-that-now-doesnt-work/#findComment-57786 Share on other sites More sharing options...
drfate Posted July 14, 2006 Author Share Posted July 14, 2006 hi there, thanks for the assistance but unfortunately it didn't work. The server guys apparently installed phpsuexec after the crash happened over a week ago and registry_global = off? Would that be causing this?regards,Andrew Quote Link to comment https://forums.phpfreaks.com/topic/14562-php-code-simple-online-text-editor-that-now-doesnt-work/#findComment-57801 Share on other sites More sharing options...
wildteen88 Posted July 14, 2006 Share Posted July 14, 2006 Use isset rather using the variable on its own, ie changeif($submit)toif(isset($submit))Now PHP will check whether this variable actually exits before using this variable, whereas before it wasnt and through up a notice, saying it cannot find the submit variable.Also you'll want to use $_POST['submit'] instead of $submit if register_globals has been turned off. You'll also want to use $_POST for your other form field variables, such $newdata will need to be $_POST['newdata'] Quote Link to comment https://forums.phpfreaks.com/topic/14562-php-code-simple-online-text-editor-that-now-doesnt-work/#findComment-57826 Share on other sites More sharing options...
ShogunWarrior Posted July 14, 2006 Share Posted July 14, 2006 Yes, it's your problem. An overall fix is:[code]$submit = ((isset($_POST['submit'])) ? ($_POST['submit']) : ( (isset($submit))? ($submit): ('') ));[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14562-php-code-simple-online-text-editor-that-now-doesnt-work/#findComment-57828 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.