Jump to content

serious doo doo.


villain222

Recommended Posts

Ok its not that serious, but i'm losing sleep regardless.

I have a situation of a page that loads a file with my current status on it.  Problem is that when I first load it, the post data hasn't been created yet and that empty data is being written to the status file that my page loads the current status from.  Otherwise its pretty slick and immediately posts.  here's the code I've tried to use to fix the problem.


$status = "selfstatus.txt";//status file

$fs = fopen($status, 'r');
//this is how my page reads the current status file contents
$statusData = fread($fs, 1000);

fclose($fs);
$text = $_POST['edit'];//updated status post from the form on the lower part of the page
if ($text == NULL) {
die();
} else {
$fp = fopen ($status, "w");

fwrite ($fp, $text);

fclose ($fp);
}

 

Here is the error for the page:  Notice: Undefined index: edit in index.php on line 14

Line 14 where my $text variable is defines. 

 

how do i get it to not right unless the form has been submitted???

Link to comment
Share on other sites

Here's how I would do it. Notice I've changed quite a bit:

<?php
$statusData = trim(file_get_contents('selfstatus.txt'));
if (isset($_POST['edit']) && strlen(trim($_POST['edit'])) > 0) {
   file_put_contents('selfstatus.txt',$_POST['edit'] . "\n");
}
?>

 

Ken

Link to comment
Share on other sites

my first part:

$status = "selfstatus.txt";//status file

$fs = fopen($status, 'r');

$statusData = fread($fs, 1000);

fclose($fs);

$text = $_POST['edit'];//updated status post

if ($text == NULL) {

die();

} else {

$text2 = $_POST['edit'];

$fp = fopen ($status, "w");

fwrite ($fp, $text2);

fclose ($fp);

}

 

My form area:

/div><p><a href="#">STATUSESES!</a><br> 



<iframe src ="editstatus.php" width="450" height="100%" frameborder=0 scrolling=auto></iframe><!--status update frame -->









<font size=1><div  id="statusedit"><b>edit </b></div>

<form id="statuseditbox" action="<?php echo $PHP_SELF; ?>" method="post"><!--status update form -->

<div>

<input type="text" name="edit" />

<input type="submit" value="update" />

</div>

</form></font>



</p>

 

here is the edit status iframe source:

<?
//this pulls the status information from the file listed below
$status = "selfstatus.txt";
$fs = fopen($status, 'r');
$statusData = fread($fs, 1000);
fclose($fs);

echo "<i> <font size=2>";
echo $statusData;
//instantly reposts file contents.

?>

 

whatcha talkin bout, Willis?

 

does that help.

 

it works while im on the page but then it rewrites when its opened for the first time

 

i know i have a redundant file read,but im not calling the first

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.