Demont Posted November 24, 2007 Share Posted November 24, 2007 I've made an attempt at a chat script, but it isn't performing exactly how I want. Yes, I am a relative newbie to PHP. I've spent hours on Hot Scripts looking for something, but nothing I found meets what I need. What this chat script is for is for a web based MUD. I've updated the code, but I am running into a snag... <!-- Begin Chat Script --> <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("DB", $con);$sql="INSERT INTO Contacts (chat) VALUES ('$_POST[chat]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } $query = mysql_query("SELECT chat FROM Contacts"); // Creates an array of items with keys corresponding to table columns... while($row = mysql_fetch_array($query)){ //Create the HTML table echo "$username said, ".$row[chat].".<br>"; } ?> <br><br><br><br><br><br><br><br> <?php include("more_footer.php"); ?> <form action="members.php" method="post"> <br /> <input type="text" name="chat"><br /> <input type="submit" value="Submit"> </form> <!-- End chat Script --> What I am trying to attempt, it to have the 'chat' displayed on the screen so all users see it, but so that it is like; 'Username said, text here.' 'Username said to, text here.' And such like that, so that say if a user supplies a command into an input field like /say, or /say to user, it will show the output like I demonstated above, and so that if the field is empty, it doesn't display any thing. You can go to http://loria.freehostia.com and see what I mean with the LOGIN-test and PASSWORD-test. Quote Link to comment https://forums.phpfreaks.com/topic/78724-solved-a-chat-script/ Share on other sites More sharing options...
Distant_storm Posted November 25, 2007 Share Posted November 25, 2007 sorry got wrong end of stick- please delete post Quote Link to comment https://forums.phpfreaks.com/topic/78724-solved-a-chat-script/#findComment-398461 Share on other sites More sharing options...
Demont Posted November 25, 2007 Author Share Posted November 25, 2007 Anyone have any advice or help to offer me here? Quote Link to comment https://forums.phpfreaks.com/topic/78724-solved-a-chat-script/#findComment-398840 Share on other sites More sharing options...
kratsg Posted November 25, 2007 Share Posted November 25, 2007 Store the username along with the contents in the database. Then pull it when you load the page. If you want it to be dynamic, read up on AJAX (meaning this becomes the wrong board for this question). Quote Link to comment https://forums.phpfreaks.com/topic/78724-solved-a-chat-script/#findComment-398846 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.