proud Posted February 26, 2007 Share Posted February 26, 2007 I'm trying to design a shoutbox for my site... This shoutbox code works good but recently i added to it a (meta tag) because i want the page to referesh every five seconds and get the new messages from the database... My problem is that the meta-tag makes the entire page refresh including the form in which i'm supposed to enter the message, so my objective is to let the part of the page which contains the form to be excluded from refreshing so how can i do that? and without needing to divide the code into two different files? <?php include( 'connect.php' ); $name = $_POST['name']; $message = $_POST['message']; $ip = $_POST['ip']; $mlen = strlen($message); $maxlength = 150; $date = date("M jS Y"); if ($_POST['submit']) { if ($name == "") { echo "<strong>Error: Please enter your nickname.</strong>"; } else if ($message == "") { echo "<strong>Error: No message to be sent.</strong>"; } else if ($mlen > $maxlength) { echo "<strong>Error: Message too long.</strong>"; } else { mysql_query("INSERT INTO shoutbox(name,message,date,ip) VALUES('$name','$message','$date','$ip')"); } } ?> <html> <head> <title>Display Messages</title> //////////<meta http-equiv="refresh" content="5;url=shoutbox.php">///////////// </head> <body> <? $query = "SELECT * FROM shoutbox ORDER BY id DESC LIMIT 20"; $result = mysql_query($query); echo "<div id=\"contentbox\">\n"; echo "<ul id=\"shoutboxmessage\">\n"; while($r = mysql_fetch_array($result)) { $name = $r['name']; $name = strip_tags($name); $message = $r['message']; $message = strip_tags($message); echo "<li><strong>>$name</strong>: $message</li>\n"; } echo "</ul>\n"; echo "</div>\n"; mysql_close($conn); ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <strong>Nickname:</strong><br/> <input type="text" name="name" maxlength="20"><br/> <strong>Message:</strong><br/> <textarea name="message"></textarea><br/> <input type="submit" name="submit" value="Shout It!"> <input type="hidden" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>"> </form> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/40245-need-some-help-with-shoutbox-code/ Share on other sites More sharing options...
Scriptor Posted February 26, 2007 Share Posted February 26, 2007 How about putting the shoutbox in another file and using an iframe? You can put the meta-tag in that other file and it should only refresh that part. Link to comment https://forums.phpfreaks.com/topic/40245-need-some-help-with-shoutbox-code/#findComment-194712 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.