• User

    chat utente registrato

    buongiorno ho creato una chat dove l'utente loggato può creare la sua chat e vedere la lista delle stanze create quando entro in chat riconosce il nome della chat ma quando scrivo in chat e do invio mi da pagina bianca non riesco a capire il perchè non inserisce il testo posto ciò che ho creato chiedo aiuto grazie

    <?php
        include "config.php";
    	include("auth_session.php");
    ?>
    <!doctype html>
    <html lang="it">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport"
              content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title><?php echo $lang['title'] ?></title>
        <link rel="stylesheet" href="bootstrap-4.0.0-dist/css/bootstrap.min.css">
    	<!-- Begin emoji-picker Stylesheets -->
        <link href="lib/css/emoji.css" rel="stylesheet">
        <!-- End emoji-picker Stylesheets -->
    	<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
    
        <!-- Begin emoji-picker JavaScript -->
        <script src="lib/js/config.js"></script>
        <script src="lib/js/util.js"></script>
        <script src="lib/js/jquery.emojiarea.js"></script>
        <script src="lib/js/emoji-picker.js"></script>
        <style type="text/css">
            .footer {
                left: 0;
                position: fixed;
                bottom: 0;
                text-align: center;
                color: white;
                width: 100%;
            }
        </style>
    </head>
    <body>
        <nav class="navbar navbar-expand-sm bg-dark navbar-dark">
            <ul class="navbar-nav">
                <li class="nav-item active">
                    <a class="nav-link" href="profilo.php"><?php echo $lang['home'] ?></a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="creachat.php"><?php echo $lang['pricing'] ?></a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#"><?php echo $lang['contact'] ?></a>
                </li>
            </ul>
        </nav>
        <div class="container" style="margin-top: 100px;">
            <div class="row justify-content-center">
                <div class="col-md-6 col-md-offset-3 text-center">
                    <h1><?php echo $lang['title'] ?></h1>	                
    			  </div>
    			   		 <?php
    						include('db.php');
    						
    						$id = $_GET['id'];
    
    						$query=mysqli_query($con,"SELECT chatname FROM chat WHERE chatname = '$id' ");
    						while($row=mysqli_fetch_array($query)){
    							
    							
    						?>  
                          
    					 
    
    
                             <?php 
    					include ("db.php");
    					
    					
    					if(!$con)
    					{
    						die(mysqli_error());
    					}
    					
    					if(isset($_POST['submit']))
    					{
    						$id = $_POST['id'];
    						$msg = trim($_POST['msg']);
    						
    						$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 id, chatname, msg, name FROM chat WHERE chatname='$id' ");
    								while($row=mysqli_fetch_array($query)){
    								{
    								
    								 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" 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>