visualizza stanze chat e accesso stanza

Imperor

Utente Attivo
25 Nov 2010
90
2
8
Roma
www.fcfclean.it
salve ho creato un sito con registrazione e login l'utente loggato può creare una stanza dove può chattare mi riconosce ogni stanza creata ma non riesco a inserire i messaggi in chat chiedo aiuto grazie posto i codici
-----------------------------------------------

PHP:
pagina dove crea il nome stanza
    </div>
                <?php
                include_once 'db.php';
                if(isset($_POST['save']))
                {     
                     $chatname = $_POST['chatname'];

                     $sql = "INSERT INTO chat (chatname, name)
                     VALUES ('$chatname','".$_SESSION['name']."')";
                     if (mysqli_query($con, $sql)) {
                        echo "New record created successfully !";
                     } else {
                        echo "Error: " . $sql . "
                " . mysqli_error($con);
                     }
                     mysqli_close($con);
                }
                ?>
           </div>
        </div>
        
         <?php
            $servername = "localhost";
            $username = "root";
            $password = "";
            $dbname = "test";
            
            // Create connection
            $conn = new mysqli($servername, $username, $password, $dbname);
            // Check connection
            if ($conn->connect_error) {
                die("Connection failed: " . $conn->connect_error);
            }
            
            $sql = "SELECT id, chatname, name, date FROM chat; ";
            $result = $conn->query($sql);
            
            while($row = $result->fetch_assoc()) {
            ?>
            
                   </div>
                     <div class="container">
                     <div class="card">
                    <table class="table">
                      <thead>
                        <tr>
                          <th scope="col">Creata da</th>
                          <th scope="col">Nome stanza</th>
                          <th scope="col">Data creata</th>
                         </tr>
                      </thead>
                      <tbody>
                        <tr>
                          <th scope="row"><?php echo $row['name']; ?></th>
                          <td><?php echo $row['chatname']; ?></td>
                          <td><?php echo $row['date']; ?></td>
                          <td><?php                     
                        echo '<td><a href="chatname.php?id=' . $row['chatname'] . '">Entra</a></td>';
                        ?></td>
                        </tr>
                        </tr>
                      </tbody>
                    </table>
        </div>
        <?php
                                }
                            
                            ?>


               </div>
            </div>           
        </div>
</body>
</html>
---------------------------------
pagina chat
         </div>
                        <?php
                        include('db.php');
                        $id = $_GET['id'];
                        $query=mysqli_query($con,"SELECT chatname FROM chat ORDER BY chatname='$id' ");
                        while($row=mysqli_fetch_array($query)){
                        
                        ?> 

                    <?php
                    include ("db.php");
                    
                    if(!$con)
                    {
                        die(mysqli_error());
                    }
                    
                    if(isset($_POST['submit']))
                    {
                        
                        $msg = trim($_POST['msg']);
                        $chatname = trim($_POST['chatname']);
                        $id = $_POST['id'];
                        
                        $sql = "insert into `chat` (chatname, msg, name) values (chatname='$id', '$msg' , '".$_SESSION['name']."', NOW())";
                        $rs = mysqli_query($con, $sql);
                        $affectedRows = mysqli_affected_rows($con);
                        
                        if($affectedRows == 1)
                        {
                            $successMsg = "Record has been saved successfully";
                        }
                    }
                    ?>
                                              
            </div>
            
                
            <div>
                <div class="panel panel-default" style="height: 400px;">
                    <div style="height:10px;"></div>
                    <span style="margin-left:10px;"><?php echo $row['chatname']; ?></span><br>
                    <span style="font-size:10px; margin-left:10px;"><i>---------------------------------------------</i></span>
                    <div style="height:10px;"></div>
                    <div id="msg" style="margin-left:10px; max-height:320px; overflow-y:scroll;">
                               <?php
                                include('db.php');
                                $id = $_GET['id'];
                                $query=mysqli_query($con,"SELECT chatname, msg, name FROM chat WHERE chatname='$id'");
                                while($row=mysqli_fetch_array($query)){
                                {
                                 echo '<td><a href="profile.php?name=' . $row['name'] . '"> Profilo </a></td>';
                                 echo $row['name'] ." ". $row['msg'] ."<br />";
                                }
                                ?>   
                    </div>
                </div>
                <div class="container">
                     <form method="post" action="chatname.php">
                    <p class="lead emoji-picker-container">
                     <input type="text" name="msg" id="msg" class="form-control" placeholder="Di la tua"data-emojiable="true">
                    </p>
                    <input type="hidden" name="chatname">
                     <input type="hidden" value="<?= $_SESSION['name'] ?>"> 
                      <input type="submit" name="submit" value="invia">
                     </form>
                </div>
           </div>
        </div>
                    
         <script>
                const msg = document.getElementById('msg');

                function appendMsg() {
                    const msg = document.getElementsByClassName('msg')[0];
                  const newMsg = msg.cloneNode(true);
                  msg.appendChild(newMsg);
                }

                function getMsg() {
                    // Prior to getting your msg.
                  shouldScroll = msg.scrollTop + msg.clientHeight === msg.scrollHeight;
                  /*
                   * Get your msg, we'll just simulate it by appending a new one syncronously.
                   */
                  appendMsg();
                  // After getting your msg.
                  if (!shouldScroll) {
                    scrollToBottom();
                  }
                }

                function scrollToBottom() {
                  msg.scrollTop = msg.scrollHeight;
                }

                scrollToBottom();

                setInterval(getMsg, 100);
                </script>
               <script>
                  $(function() {
                    // Initializes and creates emoji set from sprite sheet
                    window.emojiPicker = new EmojiPicker({
                      emojiable_selector: '[data-emojiable=true]',
                      assetsPath: 'lib/img/',
                      popupButtonClasses: 'fa fa-smile-o'
                    });
                    // Finds all elements with `emojiable_selector` and converts them to rich emoji input fields
                    // You may want to delay this step if you have dynamically created input fields that appear later in the loading process
                    // It can be called as many times as necessary; previously converted input fields will not be converted again
                    window.emojiPicker.discover();
                  });
                </script>
                <?php
                                }
                            
                            ?>
           </div>
          </div>
        </div>
      </div>
          
            





















        
        <?php
                                }
                            
                            ?>   

            </div>
          </div>
        </div>
      </div>
    
</body>
</html>
 
Discussioni simili
Autore Titolo Forum Risposte Data
I visualizza file sottocartella elimina singolo file PHP 1
S Visualizza l'errore di creazione in MSSQL Database 4
G Il mio sito dopo aver abilitato l'ssl non visualizza le immagini con indirizzi senza ssl HTML e CSS 0
L php mysql cerca e visualizza pagina PHP 0
I visualizza profilo utente utente in chat PHP 0
I [PHP] visualizza file pdf in una cartella e download PHP 7
M [Javascript] Visualizza contenuto file XML aggiornato con text scroll Javascript 0
C [PHP] Aiuto su visualizza foto da cartella PHP 6
Shyson Word 2011 non visualizza immagini Mac e Software 2
S Login, visualizza e cancella. PHP 3
pup3770 Ricerca da una pagina e visualizza in un'altra PHP 4
S Access 2007 blocco visualizza riquadro MS Access 0
J Mappa che visualizza daove sei PHP 7
M visualizza video jQuery 0
A Non visualizza google map dentro la mia app Android Sviluppo app per Android 1
D DVD da 3gb visualizza solo 700mb Windows e Software 0
M Dreamweaver non visualizza file swf nell'anteprima browser Webdesign e Grafica 0
G script Java non visualizza i decimali :( Javascript 4
L menu select che visualizza le cartelle di una cartella PHP 16
I gallery visualizza la prima immagine PHP 18
T visualizza cartella Classic ASP 4
J browser che non visualizza (visualizza solo sorgente) HTML e CSS 4
EffeElle Visualizza record php PHP 4
P Visualizza dati di una singola settimana PHP 11
G Visualizza Ordini Classic ASP 4
W Non si visualizza DataGrid su pagina Web Ajax 0
G non visualizza filmato swf in sito html HTML e CSS 2
P Plugin facebook non visualizza le immagini HTML e CSS 1
S Non visualizza l'intera lista utenti PHP 2
T problema con i css ... explorer visualizza male... HTML e CSS 2
G Visualizza foto da un db mysql PHP 60
R Cerco Script che visualizza ultimi messaggi forum Javascript 4
SolidSnake4 ezImage non visualizza l'immagine PHP 0
M IE non visualizza la pagina Classic ASP 2
L non visualizza video flv Flash 1
F HTML non lavora dal menu Visualizza x Kodemondo HTML e CSS 3
F HTML menù "visualizza" HTML e CSS 3
B l'immagine non si visualizza nell'e-mail PHP 1
R script visualizza immagine onmouse over.. Javascript 1
borgo italia visualizza html HTML e CSS 0
C IE non mi visualizza le immagini PHP 0
B non visualizza sito PHP 1
D Filmato che non si visualizza !!!! Flash 1
A mozilla non mi visualizza le immagini HTML e CSS 4
G in flash è possibile creare una finestra che visualizza una pagina html? Flash 0
C mozilla non visualizza immagini HTML e CSS 4
I Easyphp non visualizza swf PHP 1
S Non visualizza i COOKIE!!! PHP 0
M Cosa ne pensate del mio primo file PHP (verifica disponibilità stanze)? PHP 0
I salvare testo chat PHP 4

Discussioni simili