Tandem Posted July 18, 2006 Share Posted July 18, 2006 The following lines are writing entries into a text file.[code]$line = date("m.d.y") . "|" . $poster . "|" . $_POST['news'];fwrite($fp, $line);[/code]The problem is i'm getting this output in the text file:[quote]07.18.06|Tandem|07.18.06|Tandem|Some sort of message[/quote]The date and my name are being written into the text file twice and i don't know why.I guess it doesn't really matter that much as i can work around it if need be, but for the sake of cleanliness i'd like to fix it, so i'd be grateful if somebody could point out the reason.Thanks in advance -Tandem Quote Link to comment https://forums.phpfreaks.com/topic/14897-text-file-drama-o/ Share on other sites More sharing options...
hitman6003 Posted July 18, 2006 Share Posted July 18, 2006 You need to post more of your code, cause apparently you are writing to the file twice at some point and not realizing it. Quote Link to comment https://forums.phpfreaks.com/topic/14897-text-file-drama-o/#findComment-59704 Share on other sites More sharing options...
redarrow Posted July 18, 2006 Share Posted July 18, 2006 look's like the codes in a loop. Quote Link to comment https://forums.phpfreaks.com/topic/14897-text-file-drama-o/#findComment-59705 Share on other sites More sharing options...
Tandem Posted July 18, 2006 Author Share Posted July 18, 2006 [code]if (empty($_POST['news'])){if (!empty($_POST['submit'])){echo '<font face="verdana" size="1px" color="red">*You did not enter any news into the form!<br /></font>' . "\n";exit;}}if(strstr($_POST['news'],"|")) {echo '<font face="verdana" size="1px" color="red">*News cannot contain the pipe symbol - " | "<br /></font>' . "\n";exit(); }?><table width="100%" height="100%" cellspacing="10%"><tr><td align="left"><table cellspacing="0"><tr><td class="tablehead" align="center">NEWS</td></tr><tr><td class="main" align="center"><?php$poster_check = $_POST['poster'];$poster_check = mysql_query("SELECT USERNAME FROM USERS WHERE USERID='$_SESSION[userid]'");$poster = mysql_result($poster_check,0);$fp = fopen('news.txt','a');if(!$fp) {echo '<font face="verdana" size="1px" color="red">*Error Opening file!<br /></font>' . "\n"; exit(); } $line = date("m.d.y") . "|" . $poster . "|" . $_POST['news'] . "|" . $newstitle;fwrite($fp, $line); if(!fclose($fp)) {echo "Error closing file!";exit;} ?>[/code]This is eveything that corresponds to the process. Quote Link to comment https://forums.phpfreaks.com/topic/14897-text-file-drama-o/#findComment-59707 Share on other sites More sharing options...
toplay Posted July 18, 2006 Share Posted July 18, 2006 You don't show your complete code related to this.I assume you're writing this out in a loop and not accidentally calling this twice. This might be valid data and it just happens to be two lines of data!Depending on your operating system, you need to add a carriage returns (\r) or newlines (\n) or both (\r\n) to the end of the line to separate each lines output. Example:$line = date("m.d.y") . "|" . $poster . "|" . $_POST['news'] . "\n";EDIT:I notice now you posted your code. Anyway, since you're opening the file with "a" (appending), my response still applies about adding a line ending to each line of data. Quote Link to comment https://forums.phpfreaks.com/topic/14897-text-file-drama-o/#findComment-59710 Share on other sites More sharing options...
hitman6003 Posted July 18, 2006 Share Posted July 18, 2006 Your code appears fine there.However, you are not seperating the news stories from eachother...you may want to change your $line to be:[code]$line = date("m.d.y") . "|" . $poster . "|" . $_POST['news'] . "|" . $newstitle . "\n";[/code]So that each story will be on a new line. Quote Link to comment https://forums.phpfreaks.com/topic/14897-text-file-drama-o/#findComment-59712 Share on other sites More sharing options...
redarrow Posted July 18, 2006 Share Posted July 18, 2006 try that ok$line = date("m.d.y") . "|" . $poster . "|" . $news . "|" . $newstitle;fwrite($fp, $line); Quote Link to comment https://forums.phpfreaks.com/topic/14897-text-file-drama-o/#findComment-59714 Share on other sites More sharing options...
Tandem Posted July 18, 2006 Author Share Posted July 18, 2006 Yeah, it appears it wasn't doing it twice, i just didn't have it so that my posts where on new lines, and that new features were being added as, making it look like they were posted twice. Thanks for the help people! Quote Link to comment https://forums.phpfreaks.com/topic/14897-text-file-drama-o/#findComment-59718 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.