joso
May 29, 2004, 4:47pm
1
hey i’ve got s simple php script that i use to just add some text to a .txt file and it shows up on my site…but i have a problem…
check out this link http://www.band-central.net/fanlist/fanlist.php
you will see the first entry shows ok but then it only shows the first two lines of the 2nd then pushes the rest onto the next page…try posting and it will do the same…does anyone know why this is happening?
sorry forgot to mention i need 10 entries per page
this is my code for the addfan.php page :
<?php
if ($message != '')
{
$message = str_replace ("
","<br>",$message);
$message = strip_tags ($message, '<br>');
$newRow = '<br><strong>Name :</strong> ' . ($name) . '<br>
<strong>E-Mail :</strong> <a href="mailto:' . ($email) . '">' . ($email) . '</a> <br>
<strong>D.O.B :</strong> ' . ($dob) . '<br>
<strong>Location :</strong> ' . ($location) . ' <br>
<strong>Fav. Ateyu Song :</strong> ' . ($fav_song) . ' <br>
<strong>Fav. Bands :</strong> ' . ($fav_bands) . ' <br>
<strong>Message :</strong> ' . ($message) . ' <br>
<br><img src="border.jpg" width="300" height="5"><br>';
$oldRows = join ('', file ('fans.txt') );
$fileName = fopen ('fans.txt', 'w');
fputs ($fileName, $newRow . chr(13) . chr(10) . $oldRows);
fclose ($fileName);
}
include ("fanlist.php");
?>
I think the error is in your fanlist.php script. It reads 10 lines from your fans.txt file and display them.
The problem is that you want 10 complete entries. Not 10 lines.
If you can’t figure it out, post your fanlist.php script and I’ll take a look at it.
Another option could be to change the addfan.php script so one entry takes up one line in the txt file:
<?php
if ($message != '')
{
$message = str_replace ("
","<br>",$message);
$message = strip_tags ($message, '<br>');
$newRow = '<br><strong>Name :</strong> ' . ($name) . '<br>' .
'<strong>E-Mail :</strong> <a href="mailto:' . ($email) . '">' . ($email) . '</a> <br>' .
'<strong>D.O.B :</strong> ' . ($dob) . '<br>' .
'<strong>Location :</strong> ' . ($location) . ' <br>' .
'<strong>Fav. Ateyu Song :</strong> ' . ($fav_song) . ' <br>' .
'<strong>Fav. Bands :</strong> ' . ($fav_bands) . ' <br>' .
'<strong>Message :</strong> ' . ($message) . ' <br>' .
'<br><img src="border.jpg" width="300" height="5"><br>';
$oldRows = join ('', file ('fans.txt') );
$fileName = fopen ('fans.txt', 'w');
fputs ($fileName, $newRow . chr(13) . chr(10) . $oldRows);
fclose ($fileName);
}
include ("fanlist.php");
?>
thanks for you help man…thats just right im pretty new to php so i was just trying trial and error…but wasnt getting very far. thanks again
i wonder if you could help again. When i submit text, once it shows up, if i include a ’ or " then it see inserts a \ before it…is there any way you can stop this from happening?
Try adding these lines at the start of your addfan.php script. They’ll remove the slashes in the message.
if (get_magic_quotes_gpc()) {
$message = stripslashes($message);
}
You may want to run stripslashes on your other variables as well if they may contain quotes and/or apostrophes.
thanks…i was just wondering, is there an easy way to keep track of the amount of entries…just in another text file that holds the number of entries like ‘27’ or whateva…cheers
$entries = count(file('fans.txt'));
… assuming that you have one entry per line in the text file.
oh cool…how di i use that line of code…do i just insert it in the addfan.php code?
system
May 30, 2004, 5:17am
10
That depends on where you want to use the number of entries. I would think in the fanlist.php script. Something like “There are x entries in the fan list”.
But it depends on what you want to use it for…