villain222 Posted August 16, 2010 Share Posted August 16, 2010 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??? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted August 16, 2010 Share Posted August 16, 2010 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 Quote Link to comment Share on other sites More sharing options...
villain222 Posted August 16, 2010 Author Share Posted August 16, 2010 here is an error from firefox when I hit submit: Firefox doesn't know how to open this address, because the protocol (notice) isn't associated with any program. the info is being posted to a page in an iframe. is that the problem? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted August 16, 2010 Share Posted August 16, 2010 Please post all of your code. When you post a snippet and don't tell us anything about how it's being used, we can only guess at it's use. Ken Quote Link to comment Share on other sites More sharing options...
villain222 Posted August 17, 2010 Author Share Posted August 17, 2010 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 Quote Link to comment Share on other sites More sharing options...
villain222 Posted August 17, 2010 Author Share Posted August 17, 2010 kenrbnsn your solution worked after I figured out why the form wasn't submitting. Thanks, I'll have to do some dissecting on your code to figure out what is happening exactly. We can put this one to bed. Quote Link to comment 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.