Shoutbox refresh problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DaveWilson

    Shoutbox refresh problem

    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='commentSu b' 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("connec t.php");
    $link = mysql_connect(H OST,USER,PASSWO RD) 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("SE LECT * FROM shoutbox order by id DESC limit
    8");

    while($row=mysq l_fetch_array($ result))
    {

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

    }

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

    }

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

    $status = 0; //reinitialise

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

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

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

    while($row=mysq l_fetch_array($ result))
    {

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

    }

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

    }

    else {

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

    $status = 0; //reinitialise

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

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

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

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

    }

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

    }

    }

    else {

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

    while($row=mysq l_fetch_array($ result))
    {

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

    }


    ?>
    <div class="ShoutBot tom"> <img src="bl.gif" alt=""
    width="15" height="15" class="corner"
    style="display: none" /> </div>
    </div>
Working...