Jump to content


PHP CODE (simple online text editor that now doesn't work)

  • Please log in to reply
4 replies to this topic

#1 drfate

  • Members
  • PipPip
  • Member
  • 10 posts

Posted 14 July 2006 - 06:07 AM

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 3

Notice: Undefined variable: data in /home2/impulse/public_html/admin/edit.php on line 11

However, 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


if ($submit) {
$fp = fopen("data.txt", "w");
fwrite($fp, stripslashes($newdata));

$fp = fopen("data.txt", "r");
while (!feof($fp)) {
$data .= fgets($fp, 4096);



<title>simple text editor</title>

$filemod = filemtime('data.txt');
$filemodtime = date("F j Y h:i:s A", $filemod);
echo "<center>This File was last updated $filemodtime</center>";


<form action="<? print $PHP_SELF; ?>" method="post"> 
<textarea name="newdata" rows="26" cols="40">
print $data;

<input type="submit" name="submit" value="Submit"></form>

#2 toplay

  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 14 July 2006 - 06:24 AM

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 .=

Take a look at error_reporting() and display_errors php.ini settings for more info on how to stop notices.

#3 drfate

  • Members
  • PipPip
  • Member
  • 10 posts

Posted 14 July 2006 - 08:49 AM

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?

#4 wildteen88

  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 14 July 2006 - 10:34 AM

Use isset rather using the variable on its own, ie change

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']

#5 ShogunWarrior

  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 14 July 2006 - 10:43 AM

Yes, it's your problem. An overall fix is:
$submit = ((isset($_POST['submit'])) ? ($_POST['submit']) : ( (isset($submit))? ($submit): ('') ));

<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users