Ok so I'm making this shout box for my weblog and so far everything works as planned. It can read and write to the database. But when it writes to the database it overwrites the last post with the new one. Can anyone tell me how to fix this? Shout box can be found here http://zero.cd-dm.net/zero_fenix/
Oh and I can get it to get the persons IP address like I wanted it to can anyone help me with that to? It just leaves the field blank.
Read flat file and post.
Add shout.PHP Code:function get_shout() {
$filename = "data/shouts.php";
$handle = fopen($filename, "r+");
$contents = fread($handle, filesize($filename));
list($username, $comment, $unixtime) = explode("||", $contents);
$date = date("M j, Y", $unixtime);
$time = date("Y h:i a", $unixtime);
$date = "$date at $time";
echo "Posted by: <b>$username</b> on $date<br>"
."<div style=\"overflow:auto;height:40;width:100%;\">"
."$comment"
."</div>";
};
PHP Code:function add_shout() {
$name = $_POST['name'];
$comment = $_POST['comment'];
$comment = str_replace("||", "|", $comment);
$comment = str_replace('<', "<", $comment);
$comment = str_replace('>', ">", $comment);
$comment = str_replace('\"', """, $comment);
$comment = str_replace('\\\'', "´", $comment);
$date = time();
$ipaddress = $HTTP_SERVER_VARS['REMOTE_ADDR'];
$content = $name . "||" . $comment . "||" . $date . "||" . $ipaddress . "||";
$filename = "data/shouts.php";
$handle = fopen($filename, "r+");
fwrite($handle, $content);
fclose($handle);
};





Bookmarks