By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,312 Members | 1,850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,312 IT Pros & Developers. It's quick & easy.

Shoutbox refresh problem

P: n/a
Hi all,
I've built this shout box to go on my web page but have hit a
snag.
Everytime i refresh the page the last entry is reloaded onto the top
of the list. this is causing the list to become filled with the same
commentsw every time i refresh the page. I've tried resesting the
variables after they have been used but to no avial. please plese
help!! :p

The full listing is below:

<div class="Shout"> <a name="shout"></a>
<div class="ShoutTop"> <img src="tl.gif" alt="" width="15"
height="15" class="corner" style="display: none" />
<p class="subtitle" align="center">Leave your shout outs
below!</p>
<br>
<p class="text3" align="center">Fill in your name, write your
shout and hit
submit!</p>
<br>
</div>
<form action="<? echo $_SERVER['PHP_SELF'] ?>" method="post"><LABEL
for="name"><p>
Name:</LABEL></span><br>
<INPUT TYPE='TEXT' NAME='nameSub' SIZE=15 maxlength='100'
id="name" value="Name">
<br>
<LABEL for="comment"><p>Shout:</LABEL>
<br>
<INPUT TYPE='TEXT' NAME='commentSub' SIZE=15 maxlength='100'
id="comment" value="Comments">
<br>
<br>
<div class="Submit">
<input type='hidden' name='status' value='1'>
<input type="submit" name="submit" value="submit">
</div>
</form>
<?php
include("connect.php");
$link = mysql_connect(HOST,USER,PASSWORD) or die("ERROR: Could not
connect to DB");
mysql_select_db(DATABASE,$link) or die("ERROR: Could not connect to
DB");

// status

$status = $_POST['status'];
$name = $_POST['nameSub'];
$comment = $_POST['commentSub'];

//update and repopulate shoutbox
if($status == 1) {

$status = 0; //reinitialise

if($name == "" && $comment == "") {

$result = mysql_query("SELECT * FROM shoutbox order by id DESC limit
8");

while($row=mysql_fetch_array($result))
{

echo "<p class=text3>$row[name]:</p>";
echo "<p class=text4>$row[comment] <br>";

}

$name = "";
$comment = "";

}

elseif($name == "" && $comment != "") {

$status = 0; //reinitialise

$query = "INSERT INTO shoutbox (name,comment) VALUES
('Anon','".$comment."')";

$result = mysql_query($query,$link) or die("ERROR: Could not enter
data. ".mysql_error());

$result = mysql_query("SELECT * FROM shoutbox order by id DESC limit
8");

while($row=mysql_fetch_array($result))
{

echo "<p class=text3>$row[name]:</p>";
echo "<p class=text4>$row[comment] <br>";

}

$name = "";
$comment = "";

}

else {

//print "<br><br>shud be entering comments into db here<br>";
//Print "passed name: ".$name."<br>";
//Print "passed message: ".$comment."<br>";

$status = 0; //reinitialise

$query = "INSERT INTO shoutbox (name,comment) VALUES
('".$name."','".$comment."')";

$result = mysql_query($query,$link) or die("ERROR: Could not enter
data. ".mysql_error());

$result = mysql_query("SELECT * FROM shoutbox order by id DESC limit
8");

while($row=mysql_fetch_array($result))
{
echo "<p class=text3>$row[name]:</p>";
echo "<p class=text4>$row[comment] <br>";

}

$name = "";
$comment = "";

}

}

else {

$result = mysql_query("SELECT * FROM shoutbox order by id DESC limit
10");

while($row=mysql_fetch_array($result))
{

echo "<p class=text3>$row[name]:</p>";
echo "<p class=text4>$row[comment] <br>";
}

}
?>
<div class="ShoutBottom"> <img src="bl.gif" alt=""
width="15" height="15" class="corner"
style="display: none" /> </div>
</div>
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.