Jump to content

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


drfate

Recommended Posts

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

<?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>
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Use isset rather using the variable on its own, ie change
if($submit)
to
if(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']
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.