MadTechie Posted March 25, 2007 Share Posted March 25, 2007 No you need to add the code just after you //Content has value <?php if(isset($_POST['content'])) { //Page was submitted if (!$_POST['content']) { //value of content is empty $output = "There was no data entered!"; echo $output; } else { //Content has value echo "<input name='temp' type='hidden' value='$temp' />"; if(($_POST['temp'] != $_SESSION['tmp1']) ) { //the block in Content has value goes here //Content has value $content = $_POST['content']; $info = $_POST['info']; $content = language_filter($content); @$fp = fopen("project4.txt", "a"); fwrite($fp, $content."\r\n"); $info = file('project4.txt'); for ($i = 0; $i < count($info); $i++) { echo '<br><hr>'; echo nl2br(htmlentities(stripslashes(trim($info[$i])),ENT_QUOTES)); } fclose($fp); } } $_SESSION['tmp1'] = $_POST['temp']; ?> *untested Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/page/2/#findComment-214873 Share on other sites More sharing options...
Trium918 Posted March 25, 2007 Author Share Posted March 25, 2007 Ok, It entered data once. Then I refreshed the page and tried to enter data again and it would not display the data and it did not enter it into the text file. Example: Try it yourself Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/page/2/#findComment-214884 Share on other sites More sharing options...
MadTechie Posted March 25, 2007 Share Posted March 25, 2007 do you have <?php session_start(); ?> at the start of the page ? can you post the full page code again please Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/page/2/#findComment-214941 Share on other sites More sharing options...
Trium918 Posted March 25, 2007 Author Share Posted March 25, 2007 I have <?php session_start(); ?> at the start of the page. Do you want me to delect then reinsert it again? Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/page/2/#findComment-214968 Share on other sites More sharing options...
Trium918 Posted March 25, 2007 Author Share Posted March 25, 2007 Waldir, could you have a look at my code, or anyone who can help? I am getting duplicates when the page is refreshed. Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/page/2/#findComment-214992 Share on other sites More sharing options...
Waldir Posted March 25, 2007 Share Posted March 25, 2007 seems to work fine here http://www.mylabserver.com/242/morris/projects/project4.php Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/page/2/#findComment-214994 Share on other sites More sharing options...
Trium918 Posted March 25, 2007 Author Share Posted March 25, 2007 Enter the data and then refresh the page. Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/page/2/#findComment-214996 Share on other sites More sharing options...
Waldir Posted March 25, 2007 Share Posted March 25, 2007 show me your code. Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/page/2/#findComment-215002 Share on other sites More sharing options...
Trium918 Posted March 25, 2007 Author Share Posted March 25, 2007 This is the code. <form method="POST"> <table border="1" align="center" width="300"> <tr> <td colspan="2" align="center">How to Change the World?</td> </tr> <tr> <td align="center"><img src="../images/atlas.jpg" width="100" height="165" /></td> <td><textarea name = "content" cols="50" rows="10"></textarea></td> </tr> <tr> <td colspan="2"> <?php function language_filter($string) { $obscenities = array("curse","word"," foul ","language"); foreach ($obscenities as $curse_word) { if (stristr(trim($string),$curse_word)) { $length = strlen($curse_word); for ($i = 1; $i <= $length; $i++) { $stars .= "*"; } $string = eregi_replace($curse_word,$stars,trim($string)); $stars = ""; } } return $string; } if(isset($_POST['content'])) { //Page was submitted if (!$_POST['content']) { //value of content is empty $output = "There was no data entered!"; echo $output; } else { //Content has value $content = $_POST['content']; $info = $_POST['info']; $content = language_filter($content); @$fp = fopen("project4.txt", "a"); fwrite($fp, $content."\r\n"); $info = file('project4.txt'); for ($i = 0; $i < count($info); $i++) { echo '<br><hr>'; echo nl2br(htmlentities(stripslashes(trim($info[$i])),ENT_QUOTES)); } fclose($fp); } } ?> </td> </tr> <tr> <td colspan="2" align="center"><input type = submit name="submit"></td> </tr> </table> </form> Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/page/2/#findComment-215011 Share on other sites More sharing options...
Waldir Posted March 25, 2007 Share Posted March 25, 2007 try this : <?php function language_filter($string) { $obscenities = array("curse","word"," foul ","language"); foreach ($obscenities as $curse_word) { if (stristr(trim($string),$curse_word)) { $length = strlen($curse_word); for ($i = 1; $i <= $length; $i++) { $stars .= "*"; } $string = eregi_replace($curse_word,$stars,trim($string)); $stars = ""; } } return $string; } if(isset($_POST['content'])) { //Page was submitted if (!$_POST['content']) { //value of content is empty echo 'There was no data entered!'; } else { //Content has value $info = $_POST['info']; $content = language_filter($_POST['content']); @$fp = fopen("project4.txt", "a"); fwrite($fp, $content."\r\n"); fclose($fp); $_SESSION['posted'] = TRUE; header( "Location: " .$_SERVER['PHP_SELF'] ); $info = file('project4.txt'); for ($i = 0; $i < count($info); $i++) { echo '<br><hr>'; echo nl2br(htmlentities(stripslashes(trim($info[$i])),ENT_QUOTES)); } fclose($fp); } } ?> <form method="POST"> <table border="1" align="center" width="300"> <tr> <td colspan="2" align="center">How to Change the World?</td> </tr> <tr> <td align="center"><img src="../images/atlas.jpg" width="100" height="165" /></td> <td><textarea name = "content" cols="50" rows="10"></textarea></td> </tr> <tr> <td colspan="2"> <?php if($_SESSION['posted']) { @$fp = fopen("project4.txt", "a"); $info = file('project4.txt'); for ($i = 0; $i < count($info); $i++) { echo '<br><hr>'; echo nl2br(htmlentities(stripslashes(trim($info[$i])),ENT_QUOTES)); } fclose($fp); } ?> </td> </tr> <tr> <td colspan="2" align="center"><input type = submit name="submit"></td> </tr> </table> </form> *untested Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/page/2/#findComment-215018 Share on other sites More sharing options...
Trium918 Posted March 25, 2007 Author Share Posted March 25, 2007 It's entering data into the text file but it is not displaying it in the browse. Example: Click Here. Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/page/2/#findComment-215024 Share on other sites More sharing options...
Waldir Posted March 25, 2007 Share Posted March 25, 2007 <?php session_start(); function language_filter($string) { $obscenities = array("curse","word"," foul ","language"); foreach ($obscenities as $curse_word) { if (stristr(trim($string),$curse_word)) { $length = strlen($curse_word); for ($i = 1; $i <= $length; $i++) { $stars .= "*"; } $string = eregi_replace($curse_word,$stars,trim($string)); $stars = ""; } } return $string; } if(isset($_POST['content'])) { //Page was submitted if (!$_POST['content']) { //value of content is empty echo 'There was no data entered!'; } else { //Content has value $info = $_POST['info']; $content = language_filter($_POST['content']); $fp = fopen("project4.txt", "a"); fwrite($fp, $content."\r\n"); fclose($fp); $_SESSION = 'isset'; header( "Location: " .$_SERVER['PHP_SELF'] ); } } ?> <form method="POST"> <table border="1" align="center" width="300"> <tr> <td colspan="2" align="center">How to Change the World?</td> </tr> <tr> <td align="center"><img src="../images/atlas.jpg" width="100" height="165" /></td> <td><textarea name = "content" cols="50" rows="10"></textarea></td> </tr> <tr> <td colspan="2"> <?php if(isset($_SESSION)) { echo 'Form was posted'; $fp = fopen("project4.txt", "a"); $info = file('project4.txt'); for ($i = 0; $i < count($info); $i++) { echo '<br><hr>'; echo nl2br(htmlentities(stripslashes(trim($info[$i])),ENT_QUOTES)); } fclose($fp); unset($_SESSION); } ?> </td> </tr> <tr> <td colspan="2" align="center"><input type = submit name="submit"></td> </tr> </table> </form> *tested Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/page/2/#findComment-215028 Share on other sites More sharing options...
Trium918 Posted March 25, 2007 Author Share Posted March 25, 2007 Try it out Now Example: Click Here. Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/page/2/#findComment-215035 Share on other sites More sharing options...
Waldir Posted March 25, 2007 Share Posted March 25, 2007 seems to work. Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/page/2/#findComment-215037 Share on other sites More sharing options...
Trium918 Posted March 25, 2007 Author Share Posted March 25, 2007 Thanks. Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/page/2/#findComment-215039 Share on other sites More sharing options...
Trium918 Posted March 25, 2007 Author Share Posted March 25, 2007 Could someone please explain the code that was inserted into my code? <?php session_start(); //Explain $_SESSION = 'isset';//Explain header( "Location: " .$_SERVER['PHP_SELF'] );//Explain if(isset($_SESSION)) {//Explain echo 'Form was posted'; $fp = fopen("project4.txt", "a"); $info = file('project4.txt'); for ($i = 0; $i < count($info); $i++) { echo '<br><hr>'; echo nl2br(htmlentities(stripslashes(trim($info[$i])),ENT_QUOTES)); } fclose($fp); unset($_SESSION);//Explain } ?> Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/page/2/#findComment-215050 Share on other sites More sharing options...
MadTechie Posted March 26, 2007 Share Posted March 26, 2007 read up on sessions http://uk2.php.net/manual/en/ref.session.php Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/page/2/#findComment-215333 Share on other sites More sharing options...
redbullmarky Posted March 26, 2007 Share Posted March 26, 2007 slightly off topic. when posting lots of code, please use the tags instead of the tags as it makes things a tonne easier to read. cheers Link to comment https://forums.phpfreaks.com/topic/44050-solved-why-does-it-do-what-it-does/page/2/#findComment-215376 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.