Jump to content

text file drama :o


Tandem

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/14897-text-file-drama-o/
Share on other sites

[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.
Link to comment
https://forums.phpfreaks.com/topic/14897-text-file-drama-o/#findComment-59707
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/14897-text-file-drama-o/#findComment-59710
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.