I have a chat script that I made, but...It doesn't work like I'd like it to. I can post a message, and it shows up where I want it to, yet, when I put another message, it deletes the previous one, which I don't want.

I wan't it to be like, a BB kind of, but like say 'Person a says, blah blah'. Like that, not a true BB though.

Here's my code I have.

<!-- 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());
  }

echo $_POST[chat];  
?> <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 -->

    There are many scripts like this available for free! why bother reinventing the wheel? Search http://hotscripts.com for a script that fits what you want.

      I need to 'reinvent' the wheel as you put it, and 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 -->

      I think I am doing the $query wrong...

        It's very difficult to understand that code - if you could use the board's PHP tags around it and add some spacing, that would be very beneficial. I'm guessing what you'll want to do is read the current DB, then insert the new chat line, and then echo them both out. You currently only echo out the most recent entry.

          Write a Reply...