I am trying to create a PHP chat on a free forum service (smfforfree).
Here is a link to it:
http://smctest.smfforfree3.com/pages/smctest/test.php
There are two problems:
1. When you click the Send Button, it brings you to the shout.php file.
2. The shouts don't show up. Could that be because I am using the same database for another page?
Here are the files I have:
database.php
shout.phpCode:<?php $db_user = "3823_simchat"; $db_pass = "--------------"; $db_database = "3823_simchat"; $db_host = "mysql"; $db_connect = mysql_connect ($db_host, $db_user, $db_pass); $db_select = mysql_select_db ($db_database); ?>
shoutbox.phpCode:<?php require("database.php"); function secure($string){ $string = strip_tags($string); $string = trim($string); $string = htmlspecialchars($string); $string = stripslashes($string); $string = mysql_real_escape_string($string); return $string; } $message = secure($_POST['msg']); $username = secure($_POST['postee']); if($message == ""){ header("Location: shoutbox.php"); exit; } $date = date("Y-m-d H:i:s",time()); mysql_query("INSERT INTO rawr(poster,message,date) VALUES('$username','$message','$date')") or trigger_error("Error querying database. Please contact the administrator."); header("Location: shoutbox.php"); mysql_close($db_connect); ?>
You will notice that in the shoutbox.php I use PHP and javascript.Code:<?php require("database.php"); $the_box = mysql_query("SELECT * FROM `rawr` ORDER BY date DESC LIMIT 0,40"); $chat_rows = mysql_num_rows($the_box); if($chat_rows == 0){ $Mess = "No Messages"; } while($msz = mysql_fetch_array($the_box)){ $Mess = $msz['poster'] . "(" . date('M jS, Y, g:i:s A',strtotime($msz['date']) - 5 * 60 * 60) . "): " . $msz['message'] . "<br />"; } ?> var name = document.getElementsByTagName("span"); for(v=0;v<name.length;v++){ if(name[v].innerHTML.match(/Hello <b>(.*)<\/b>/i)){ var Username = RegExp.$1; };}; var Shoutbox = ""; Shoutbox += "<form action='http://yort124.ulmb.com/smfshout/shout.php' method='POST'>"; Shoutbox += ""; Shoutbox += "<table width='500px'>"; Shoutbox += "<tr><td width='100%' height='100px'>"; Shoutbox += "<div style='overflow: auto; height: 300px; width: 100%; border: 1px solid black;' id='shoutarea'>"; Shoutbox += "<?php echo $Mess; ?>"; Shoutbox += "</div></td></tr>"; Shoutbox += "<tr><td><textarea type='text' name='msg' width='100%'></textarea></td></tr>"; Shoutbox += "<tr><td><input type='submit' name='submit' value='Send'><input type='button' onclick='javascript:window.location.reload();' value='Reload'/><input type='hidden' value='" + Username + "' name='postee'></td></tr>"; Shoutbox += "</table>"; Shoutbox += "</form>"; document.write(Shoutbox);
Anway, like I said above. When I click on the Send button, it sends me to the shout.php file.
I know it is because of the header("Location: shoutbox.php"); part, but how would I make it so it sends the information, and still goes back to the page it is on?



Reply With Quote
Bookmarks