Heres my problem: I set up a very basic message board that includes fields for name, e-mail etc and lastly has an area for comments. If a user types all in one line and lets wordwrap do its thing it comes out fine. But if the user uses the enter key to start a new line once the data is inserted into my database it messes up the lines. So that when its read back its posted as multiple entries with the lines after the enter press being inserted into the next entry name, e-mail etc.
This is my first try at php and am just using a plain text database (plain tile is called?) So my question basicly how do I avoid this? Something I can do remove/ignore any <CR> when inserting the data...or someway to retrieve the message properly and have it know when the message ends and the next one starts propery?
Heres the basic code i used for inserting:
{
$guestentry = "$guest|$email|$url|$message|$posted_on\n";
$file = fopen($data,"a");
if(flock($file,2))
fputs($file,$guestentry);
else
exit("Error: couldn't open file");
if(flock($file,3))
fclose($file);
else
exit("Error: couldn't open file");
$entered = TRUE;
}
_______
and for retrieving:
if (file_exists($data))
{
$afile = file($data);
for($num = 0; $num < count($afile); $num++)
{
$bfile = explode("|",$afile[$num]);
echo "<br><div align=\"center\">";
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\" width=\"85%\">";
echo "<td width=\"10%\" bgcolor=\"$guestinfo_tablecolor\" align=\"right\" valign=\"top\">";
echo "<p align=\"right\"><font color=\"$tfont\"><b>Last:</b></font><br>";
echo "<b><font color=\"$tfont\">By</font>:</b><br>";
echo "<font color=\"$tfont\"><b>E-Mail:<br>Homepage:</b></font></td>";
echo "<td width=\"50%\" bgcolor=\"$guestinfo_tablecolor\" valign=\"top\">";
echo "<font color=\"$guestinfo_fontcolor\">$bfile[4]<br>$bfile[0]<br>$bfile[1]<br>$bfile[2]</td></tr></table></div>";
echo "<div align=\"center\">";
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\" width=\"85%\">";
echo "<tr>";
echo "<td width=\"10%\" bgcolor=\"$messagebody_tablecolor\" valign=\"top\" align=\"right\"><font color=\"$tfont\"><b>Message:</b></font></td>";
echo "<td width=\"65%\" valign=\"top\" bgcolor=\"$messagebody_tablecolor\">$bfile[3]</td></tr></table></div>";
echo "<hr>";
}
}
else
{
echo "<tr><td>Couldn't open $data</td></tr>";
}
?>
Any help would be appreciated, and remeber Im a newbie
Myros
This is my first try at php and am just using a plain text database (plain tile is called?) So my question basicly how do I avoid this? Something I can do remove/ignore any <CR> when inserting the data...or someway to retrieve the message properly and have it know when the message ends and the next one starts propery?
Heres the basic code i used for inserting:
{
$guestentry = "$guest|$email|$url|$message|$posted_on\n";
$file = fopen($data,"a");
if(flock($file,2))
fputs($file,$guestentry);
else
exit("Error: couldn't open file");
if(flock($file,3))
fclose($file);
else
exit("Error: couldn't open file");
$entered = TRUE;
}
_______
and for retrieving:
if (file_exists($data))
{
$afile = file($data);
for($num = 0; $num < count($afile); $num++)
{
$bfile = explode("|",$afile[$num]);
echo "<br><div align=\"center\">";
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\" width=\"85%\">";
echo "<td width=\"10%\" bgcolor=\"$guestinfo_tablecolor\" align=\"right\" valign=\"top\">";
echo "<p align=\"right\"><font color=\"$tfont\"><b>Last:</b></font><br>";
echo "<b><font color=\"$tfont\">By</font>:</b><br>";
echo "<font color=\"$tfont\"><b>E-Mail:<br>Homepage:</b></font></td>";
echo "<td width=\"50%\" bgcolor=\"$guestinfo_tablecolor\" valign=\"top\">";
echo "<font color=\"$guestinfo_fontcolor\">$bfile[4]<br>$bfile[0]<br>$bfile[1]<br>$bfile[2]</td></tr></table></div>";
echo "<div align=\"center\">";
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\" width=\"85%\">";
echo "<tr>";
echo "<td width=\"10%\" bgcolor=\"$messagebody_tablecolor\" valign=\"top\" align=\"right\"><font color=\"$tfont\"><b>Message:</b></font></td>";
echo "<td width=\"65%\" valign=\"top\" bgcolor=\"$messagebody_tablecolor\">$bfile[3]</td></tr></table></div>";
echo "<hr>";
}
}
else
{
echo "<tr><td>Couldn't open $data</td></tr>";
}
?>
Any help would be appreciated, and remeber Im a newbie
Myros