Jump to content


Photo

text file drama :o


  • Please log in to reply
7 replies to this topic

#1 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 18 July 2006 - 12:28 AM

The following lines are writing entries into a text file.

$line = date("m.d.y") . "|" . $poster . "|" . $_POST['news'];
fwrite($fp, $line);

The problem is i'm getting this output in the text file:

07.18.06|Tandem|07.18.06|Tandem|Some sort of message


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

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 18 July 2006 - 12:38 AM

You need to post more of your code, cause apparently you are writing to the file twice at some point and not realizing it.

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 18 July 2006 - 12:40 AM

look's like the codes in a loop.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 18 July 2006 - 12:42 AM

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;
}   

?>

This is eveything that corresponds to the process.

#5 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 18 July 2006 - 12:45 AM

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.


#6 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 18 July 2006 - 12:47 AM

Your code appears fine there.

However, you are not seperating the news stories from eachother...you may want to change your $line to be:

$line = date("m.d.y") . "|" . $poster . "|" . $_POST['news'] . "|" . $newstitle . "\n";

So that each story will be on a new line.

#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 18 July 2006 - 12:48 AM

try that ok

$line = date("m.d.y") . "|" . $poster . "|" . $news . "|" . $newstitle;
fwrite($fp, $line);
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 18 July 2006 - 12:53 AM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users