View Full Version : shoutbox not working?
driz
December 4th, 2007, 07:57 PM
-
hl
December 4th, 2007, 08:20 PM
$fstring=$date . "|" . $time . "|" . $name . "|" . $comments . "|";
Change that to
$fstring="\r\n" . $date . "|" . $time . "|" . $name . "|" . $comments . "|";
and then try adding new entries.
driz
December 4th, 2007, 09:46 PM
that didnt work, it just threw up an error? any ideas? x
hl
December 4th, 2007, 09:51 PM
What's the error and post the new code..?
driz
December 4th, 2007, 10:06 PM
ERROR:
Parse error: syntax error, unexpected '=' in /home/driz/public_html/shoutbox/index.php on line 16
by replacing the code you said above.x
hl
December 4th, 2007, 10:28 PM
Paste the code as it is now with my change. I feel like you pasted it wrong.
driz
December 5th, 2007, 05:40 AM
-
driz
December 5th, 2007, 05:50 PM
Updates? Its still only displaying 1 entry from the text file. x
driz
December 6th, 2007, 11:50 AM
Hello?
simplistik
December 6th, 2007, 12:17 PM
Can you upload your sample txt file please?
Seb Hughes
December 6th, 2007, 01:44 PM
if($submit!="submit")
{
$filecontents=file($filename);
foreach($filecontents as $line)
{
$data=explode("|" , $line);
//print ($data [0]);
print("<div class=\"entry\">");
print("<p>" . $data[2] . "<span class=\"datetime\"><br/>" . $data[0] . "-" . $data[1] . "</span></p>");
print("<p class=\"comment\">" . $data[3] . "</p><hr />");
print("</div>");
};
};
Why do you have ; after the } ?.
Also you have to use foreach with an array and it doesnt seem like you are using an array with it. I might be talking crap.
Edit: 3 records showing now sorta, but they are messed up. As it shows a time as a name :P
simplistik
December 6th, 2007, 02:11 PM
well personally this is how I'd handle it
if( $submit == "submit" )
{
//save to text file
$fp = fopen($filename, 'a+');
$fstring = "<!--post-->" . $date . "|" . $time . "|" . $name . "|" . $comments . "\n\r";
fwrite($fp, $fstring);
fclose($fp);
};
if( $submit != "submit" )
{
$filecontents = file_get_contents( $filename );
$entries = explode('<!--post-->', $filecontents );
foreach ( $entries as $entry )
{
$data = explode('|', $entry);
if ( !empty($entry) )
{
echo '<div class="entry">';
echo '<p>' . $data[2] . '<span class="datetime"><br/>' . $data[0] . '-' . $data[1] . '</span></p>';
echo '<p class="comment">' . $data[3] . '</p><hr />';
echo '</div>'."\n\n";
}
}
};
where my text file would look something like
<!--post--> Dec 21 2007 | 12:54 PM | Name | Comments will go here
<!--post--> Dec 21 2007 | 12:54 PM | Name2 | Comments2 will go here
<!--post--> Dec 21 2007 | 12:54 PM | Name3 | Comments3 will go here
<!--post--> Dec 21 2007 | 12:54 PM | Name4 | Comments4 will go here
driz
December 6th, 2007, 04:08 PM
i get this error:
Parse error: syntax error, unexpected T_VARIABLE in /home/driz/public_html/shoutbox/index.php on line 13
simplistik
December 6th, 2007, 04:31 PM
what's line 13?
driz
December 6th, 2007, 05:16 PM
-
simplistik
December 6th, 2007, 05:54 PM
<?php
$filename = "guestbook.txt";
$submit = $_POST['submit'];
if( $submit == "submit" )
{
$date = date('Y F d');
$time = date('g:i A');
//print ($date . " <br/> " . $time);
$name = strip_tags($_POST['name']);
$comments = stripslashes( htmlentities($_POST['comments'], ENT_NOQUOTES) );
//save to text file
$fp = fopen( $filename, 'a' );
$fstring = "<!--post-->" . $date . "|" . $time . "|" . $name . "|" . $comments . "\n\r";
fwrite( $fp, $fstring );
fclose( $fp );
header("Location: ".$_SERVER['PHP_SELF']);
};
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>php shoutbox</title>
<style type="text/css" rel="stylesheet">
* { border: 0; margin: 0; padding: 0; }
body { margin: 20px; background: #151515; }
#container { width: 950px; margin: 0 auto; }
input[type=text] { background: #aaaaaa; font-size: 30px; width: 99%; padding: 5px; }
input[type=submit] { font-size: 18px; }
textarea { background: #aaaaaa; font-size: 18px; width: 99%; height: 200px; padding: 5px; }
p { font-family: "Century Gothic"; font-size: 18px; color: #2ec2e1; }
p.comment { font-family: "Verdana"; font-size: 14px; color: #aaaaaa; }
label { font-family: "Verdana"; font-size: 16px; color: #aaaaaa; text-transform: lowercase; }
legend { background: #222222; padding: 2px 20px; font-family: "Century Gothic"; font-size: 18px; color: #ff008a; }
fieldset { border: #222222 1px solid; background: #101010; padding: 20px; }
hr { margin: 10px 0; border: 0; border-top: #000000 1px solid; border-bottom: #222222 1px solid; }
div.entry { border: #222222 1px solid; padding: 20px; }
</style>
</head>
<body>
<div id="container">
<?php
if( $submit != "submit" )
{
$filecontents = file_get_contents( $filename );
$entries = explode('<!--post-->', $filecontents );
foreach ( $entries as $entry )
{
$data = explode('|', $entry);
if ( !empty($entry) )
{
echo '<div class="entry">';
echo '<p>' . $data[2] . '<span class="datetime"><br/>' . $data[0] . ' – ' . $data[1] . '</span></p>';
echo '<p class="comment">' . nl2br($data[3]) . '</p><hr />';
echo '</div>'."\n\n";
}
}
};
?>
<form id="form1" name="form1" method="post" action="index.php">
<fieldset><legend>add to the shoutbox</legend>
<label>Name</label>
<input type="text" name="name" />
<br /><br />
<label>Comment Box</label>
<textarea name="comments"></textarea>
<br /><br />
<input type="submit" name="submit" value="submit" />
</fieldset>
</form>
</div>
</body>
</html>
simplistik
December 7th, 2007, 01:46 PM
lame... can take the time to delete your posts but not take the time to thank anyone. *note to self make sure to quote all of driz's complete posts
Seb Hughes
December 7th, 2007, 08:06 PM
This guys doesn't deserve to be helped again if he deletes his main post.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.