PlagueInfected Posted August 13, 2009 Share Posted August 13, 2009 For some reason, when I make a post the file text will show however when I pull up my desired page. It will not update, the page stays blank. <fieldset> <legend>Updating page on <?php echo date("l, F d, Y"); ?></legend> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> Administrator Name: <input type="text" name="name" /> Subject: <input type="text" name="subject" /> Text: <input type="text" name="textarea" /> <input type="submit" value="submit" /> <input type="reset" value="reset" /> </form> </fieldset> <?php if (isset($_POST['name']) && $_POST['subject'] && $_POST['textarea']) { $root = $_SERVER['DOCUMENT_ROOT']; $file_name = "$root/updates.html"; $time = date("l, F d, Y"); $fp = fopen($file_name, 'a'); fwrite($fp, '<div class="name">Update by: '. $_POST['name'].'</div>'); $fp = fopen($file_name, 'a'); fwrite($fp, '<div class="subject">Subject: '. $_POST['subject'].'</div>'); $fp = fopen($file_name, 'a'); fwrite($fp, '<div class="mainsubject"> '. $_POST['textarea']."</div>");; fclose($fp); print 'page updated!' and include("$file_name"); } ?> my code works however i dont know why it will not update onto the page i chose to write it on, does the code look right or am i missing something Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/ Share on other sites More sharing options...
DEVILofDARKNESS Posted August 13, 2009 Share Posted August 13, 2009 In first place I would copy-paste the php code above the actually html code, (this will probably not change the effect, but it's more clean the $file_name contains a $ inside the quotes, is this possible? Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-897078 Share on other sites More sharing options...
TeNDoLLA Posted August 13, 2009 Share Posted August 13, 2009 First of all you should use the isset() function for each POST variable in your if clause not just the first one (might lead into some mysterious behavioir, didnt test it though). Second you don't need to open the file everytime you write new info to it, one open is enough until you close the file handle. Third do not use PHP_SELF, use $_SERVER['SCRIPT_NAME'] instead since PHP_SELF is vulnerable to XSS attacks if not used properly. Fourth I think that include should be: include($file_name); Fifth I don't know if that 'and' thing works, atleast I have never seen it being used before (if it's not ok you should print on one line and include in another). Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-897084 Share on other sites More sharing options...
TeNDoLLA Posted August 13, 2009 Share Posted August 13, 2009 About what I wrote you could try.. include: <?php $filename = $_SERVER['DOCUMENT_ROOT'] . '/updates.html'; // ....... print 'page updated'; include($filename); Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-897085 Share on other sites More sharing options...
DEVILofDARKNESS Posted August 13, 2009 Share Posted August 13, 2009 That's all true , and I also believe that the 'and' should dissapear and just do the include on the next line just as Tendola said. Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-897095 Share on other sites More sharing options...
PlagueInfected Posted August 13, 2009 Author Share Posted August 13, 2009 I tried what you all suggested, I include the file...it appears when the page loads however when I go to the actual link, the post will not appear. Here is how I updated the code <?php $root = $_SERVER['DOCUMENT_ROOT']; $file_name = $_SERVER['DOCUMENT_ROOT'] . '/updates.html'; $time = date("l, F d, Y"); if (isset($_POST['name'])) { $fp = fopen($file_name, "a"); fwrite($fp, '<div class=\"name">Update by: '. $_POST['name'].'</div><br />'); } if (isset($_POST['subject'])){ $fp = fopen($file_name, "a"); fwrite($fp, '<div class=\"subject">Subject: '. $_POST['subject'].'</div><br />'); } if (isset($_POST['textarea'])){ $fp = fopen($file_name, "a"); fwrite($fp, '<div class=\"mainsubject"> '. $_POST['textarea']."</div><br />"); fclose($fp); print 'page updated'; } include($file_name); ?> <fieldset> <legend>Updating page on <?php echo date("l, F d, Y"); ?></legend> <form action="<?php $_SERVER['SCRIPT_NAME']; ?>" method="post"> Administrator Name: <input type="text" name="name" /> Subject: <input type="text" name="subject" /> Text: <input type="text" name="textarea" /> <input type="submit" value="submit" /> <input type="reset" value="reset" /> </form> </fieldset> Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-897096 Share on other sites More sharing options...
TeNDoLLA Posted August 13, 2009 Share Posted August 13, 2009 Try this.. notice how the textarea is used btw, you used it in wrong way. Also notice the added 'echo' in the forms action attribute before $_SERVER['SCRIPT_NAME']. Without that echo the action of the form is blank. <?php $fileName = $_SERVER['DOCUMENT_ROOT'] . '/updates.html'; // Do a dump and see if the path to the file is correct // (remove the line below when you don't need it anymore). var_dump($fileName); $time = date("l, F d, Y"); if (isset($_POST['name']) && isset($_POST['subject']) && isset($_POST['textarea'])) { $fp = fopen($fileName, "a"); fwrite($fp, '<div class="name">Update by: ' . $_POST['name'] . '</div><br />'); fwrite($fp, '<div class="subject">Subject: ' . $_POST['subject'] . '</div><br />'); fwrite($fp, '<div class="mainsubject"> ' . $_POST['textarea'] . '</div><br />'); fclose($fp); echo 'Page updated'; } include($fileName); ?> <fieldset> <legend>Updating page on <?php echo date("l, F d, Y"); ?></legend> <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="POST"> Administrator Name: <input type="text" name="name" /> Subject: <input type="text" name="subject" /> Text: <textarea name="textarea"></textarea> <input type="submit" value="submit" /> <input type="reset" value="reset" /> </form> </fieldset> Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-897101 Share on other sites More sharing options...
PlagueInfected Posted August 13, 2009 Author Share Posted August 13, 2009 done it, it works but when I go to the link that is on the site it does not appear and I need the include of the filename to appear to visitors for current events and updates. here is the direct link it is going to http://plagueinfected.com/admin/updates.html and i used the same code you gave me, it works but it doesnt post onto the html page Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-897107 Share on other sites More sharing options...
DEVILofDARKNESS Posted August 13, 2009 Share Posted August 13, 2009 That link doesn't work in my browser... Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-897114 Share on other sites More sharing options...
TeNDoLLA Posted August 13, 2009 Share Posted August 13, 2009 Have you manually checked the html file contents after posting data to it? Is the data there as it should be? I looked the source and the source is blank. Btw do you have error display on? So you see if there is errors in your code. If not, put this in the beginning of your php file(s). error_reporting(E_ALL); ini_set('display_errors', 1); Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-897117 Share on other sites More sharing options...
PlagueInfected Posted August 13, 2009 Author Share Posted August 13, 2009 tried that too, still the same deal Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-897137 Share on other sites More sharing options...
darkfreaks Posted August 13, 2009 Share Posted August 13, 2009 instead of: <?php include($file);?> try: <?php readfile($file);?> Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-897179 Share on other sites More sharing options...
PlagueInfected Posted August 13, 2009 Author Share Posted August 13, 2009 i can view it, but it wont write onto the page Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-897721 Share on other sites More sharing options...
darkfreaks Posted August 14, 2009 Share Posted August 14, 2009 Try: <?php ini_set('error_reporting',E_ALL); // error reporting on $fileName = $_SERVER['DOCUMENT_ROOT'] . '/updates.html'; // Do a dump and see if the path to the file is correct // (remove the line below when you don't need it anymore). var_dump($fileName); $time = date("l, F d, Y"); //check to see if posts are set or not empty if (isset($_POST['name'])|| isset($_POST['subject'])|| isset($_POST['textarea']) ||!empty($_POST['textarea'])||!empty($_POST['subject'])||!empty($_POST['name'])) { $divname='<div class="name">Update by: ' . $_POST['name'] . '</div><br />'; $divsubject='<div class="subject">Subject: ' . $_POST['subject'] . '</div><br />'; $divtextarea='<div class="mainsubject"> ' . $_POST['textarea'] . '</div><br />'; $fp = fopen($fileName, "r+"); // open socket for read and write fwrite($fp,$divname); fwrite($fp,$divsubject); fwrite($fp,$divtextarea); fclose($fp); echo 'Page updated'; } include($fileName); ?> <fieldset> <legend>Updating page on <?php echo date("l, F d, Y"); ?></legend> <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="POST"> Administrator Name: <input type="text" name="name" /> Subject: <input type="text" name="subject" /> Text: <textarea name="textarea"></textarea> <input type="submit" value="submit" /> <input type="reset" value="reset" /> </form> </fieldset> Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-897734 Share on other sites More sharing options...
PlagueInfected Posted August 14, 2009 Author Share Posted August 14, 2009 the script you sent me, doesn't display anything Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-897740 Share on other sites More sharing options...
darkfreaks Posted August 14, 2009 Share Posted August 14, 2009 now what do you get? <?php ini_set('error_reporting',E_ALL); // error reporting on $fileName = $_SERVER['DOCUMENT_ROOT'] . '/updates.html'; // Do a dump and see if the path to the file is correct // (remove the line below when you don't need it anymore). var_dump($fileName); $time = date("l, F d, Y"); //check to see if posts are set or not empty if (isset($_POST['name'])|| isset($_POST['subject'])|| isset($_POST['textarea']) ||!empty($_POST['textarea'])||!empty($_POST['subject'])||!empty($_POST['name'])) { $divname='<div class="name">Update by: ' . $_POST['name'] . '</div><br />'; $divsubject='<div class="subject">Subject: ' . $_POST['subject'] . '</div><br />'; $divtextarea='<div class="mainsubject"> ' . $_POST['textarea'] . '</div><br />'; //check to see if file is even writtable if (is_writable($fileName)) { if (!$handle = fopen($fileName, 'r+')) { echo "Cannot open file ($filenName)"; exit; } $fp = fopen($fileName, "r+"); // open socket for read and write // Write $somecontent to our opened file. if (fwrite($fp, $divname) === FALSE) { echo "Cannot write to file ($fileName)"; exit; } elseif(fwrite($fp, $divsubject) === FALSE) { echo "Cannot write to file ($fileName)"; exit;} elseif(fwrite($fp, $divtextarea) === FALSE) { echo "Cannot write to file ($fileName)"; exit;} fwrite($fp,$divname); fwrite($fp,$divsubject); fwrite($fp,$divtextarea); fclose($fp); echo 'Page updated'; } } else{ echo "The file $fileName is not writable"; } include($fileName); ?> <fieldset> <legend>Updating page on <?php echo date("l, F d, Y"); ?></legend> <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="POST"> Administrator Name: <input type="text" name="name" /> Subject: <input type="text" name="subject" /> Text: <textarea name="textarea"></textarea> <input type="submit" value="submit" /> <input type="reset" value="reset" /> </form> </fieldset> Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-897756 Share on other sites More sharing options...
PlagueInfected Posted August 14, 2009 Author Share Posted August 14, 2009 still doesn't write to the html page Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-897812 Share on other sites More sharing options...
darkfreaks Posted August 14, 2009 Share Posted August 14, 2009 is it outputting any error? if so which one? we need to know what it is outputting if anything in ordder to determine why it isnt writing. something i noticed but your path is wrong. <?php // making sure the file is in the admin directory $base='http://plagueinfected.com/'; $filename = $base'admin/updates.html';?> Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-898275 Share on other sites More sharing options...
PlagueInfected Posted August 15, 2009 Author Share Posted August 15, 2009 outputting no errors, and the code still doesn't write Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-898850 Share on other sites More sharing options...
darkfreaks Posted August 15, 2009 Share Posted August 15, 2009 echo out $fileName make sure it is outputting the correct path. also try: <?php $fp = fopen($fileName, "w+t"); // write and write text to file ?> Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-898852 Share on other sites More sharing options...
darkfreaks Posted August 15, 2009 Share Posted August 15, 2009 figured it out you need to be using the GET method instead of POST or nothing will copy over. Link to comment https://forums.phpfreaks.com/topic/170047-php-form-not-posting-into-my-file/#findComment-898899 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.