Results 1 to 4 of 4

Thread: I need helps on chat application in php

  1. #1
    Join Date
    Sep 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I need helps on chat application in php

    My name is Fredrick. Am a second year student of Computer Engineering. Am writing an assignment/project on just basic chat application using php.

    and I needs help, I have a working chat application in php, I have a javascript sound notification to be added to the chat whenever a chat text message is sent. I also have a javascript to display users typing a chat text.

    My problem is how to integrate the sound notification and the user typing a text into the chat . can you help me to integrate it so I can post it now.

    Thank you

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    We have very strict rules here about not doing homework for anyone.

    However, if you can ask a specific question we may be able to help with that.

    In this case, I don't understand the problem: some event occurs when there is a new message. When that event occurs, you should play a sound. What is the problem?
    1. Do you know when there is a new message?
    2. Do you know how to modify that event so that it calls a function like playsound()?
    3. Do you know how to play a sound?
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Sep 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33 View Post
    We have very strict rules here about not doing homework for anyone.

    However, if you can ask a specific question we may be able to help with that.

    In this case, I don't understand the problem: some event occurs when there is a new message. When that event occurs, you should play a sound. What is the problem?
    1. Do you know when there is a new message?
    2. Do you know how to modify that event so that it calls a function like playsound()?
    3. Do you know how to play a sound?
    Below is the code. when i try to integrate the sound into chat application. the sound stops working
    Code:
    <?php 
    session_start();
    
    if(isset($_POST['submit']))
    {
    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("chat", $con);
    		$message=$_POST['message'];
    		$sender=$_POST['sender'];
    		mysql_query("INSERT INTO message(message, sender)VALUES('$message', '$sender')");
    }
    
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Simple Chat</title>
    <script language="javascript" src="jquery-1.2.6.min.js"></script>
    <script language="javascript" src="jquery.timers-1.0.0.js"></script>
    <script type="text/javascript">
    
    $(document).ready(function(){
       var j = jQuery.noConflict();
    	j(document).ready(function()
    	{
    		j(".refresh").everyTime(1000,function(i){
    			j.ajax({
    			  url: "refresh.php",
    			  cache: false,
    			  success: function(html){
    				j(".refresh").html(html);
    			  }
    			})
    		})
    		
    	});
    	j(document).ready(function() {
    			j('#post_button').click(function() {
    				$text = $('#post_text').val();
    				j.ajax({
    					type: "POST",
    					cache: false,
    					url: "save.php",
    					data: "text="+$text,
    					success: function(data) {
    						alert('data has been stored to database');
    					}
    				});
    			});
    		});
       j('.refresh').css({color:"green"});
    });
    </script>
    <style type="text/css">
    .refresh {
        border: 1px solid #3366FF;
    	border-left: 4px solid #3366FF;
        color: green;
        font-family: tahoma;
        font-size: 12px;
        height: 225px;
        overflow: auto;
        width: 400px;
    	padding:10px;
    	background-color:#FFFFFF;
    }
    #post_button{
    	border: 1px solid #3366FF;
    	background-color:#3366FF;
    	width: 100px;
    	color:#FFFFFF;
    	font-weight: bold;
    	margin-left: -105px; padding-top: 4px; padding-bottom: 4px;
    	cursor:pointer;
    }
    #textb{
    	border: 1px solid #3366FF;
    	border-left: 4px solid #3366FF;
    	width: 320px;
    	margin-top: 10px; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; width: 415px;
    }
    #texta{
    	border: 1px solid #3366FF;
    	border-left: 4px solid #3366FF;
    	width: 410px;
    	margin-bottom: 10px;
    	padding:5px;
    }
    p{
    border-top: 1px solid #EEEEEE;
    margin-top: 0px; margin-bottom: 5px; padding-top: 5px;
    }
    span{
    	font-weight: bold;
    	color: #3B5998;
    }
    </style>
    </head>
    <body>
    <form method="POST" name="" action="">
    <input name="sender" type="text" id="texta" value="<?php echo $sender ?>"/>
    <div class="refresh">
    <?php
    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("chat", $con);
    
    $result = mysql_query("SELECT * FROM message ORDER BY id DESC");
    
    
    while($row = mysql_fetch_array($result))
      {
      echo '<p>'.'<span>'.$row['sender'].'</span>'. '&nbsp;&nbsp;' . $row['message'].'</p>';
      }
    
    mysql_close($con);
    ?>
    
    </div>
    <input name="message" type="text" />
    <input name="submit" type="submit" value="Chat" />
    </form>
    </body>
    </html>
    sound.html5


    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>chat Sound</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
    $(function(){  
    	$("#chatData").focus(); 
      $('<audio id="chatAudio"><source src="notify.ogg" type="audio/ogg"><source src="notify.mp3" type="audio/mpeg"><source src="notify.wav" type="audio/wav"></audio>').appendTo('body');
      $("#trig").on("click",function(){
        var a = $("#chatData").val().trim();
        if(a.length > 0){
    	$("#chatData").val('');   
    	$("#chatData").focus(); 
         $("").html('<span></span>').appendTo("#chatMessages");
    	  $("#chat").animate({"scrollTop": $('#chat')[0].scrollHeight}, "slow");
          $('#chatAudio')[0].play();
        }
      });
    });
    </script>
    
    </head>
    <body>
    	
    	
    
    	
        <div id='chat'>
            
                <ul id='chatMessages'>
                    
                </ul>
           </div>
    		<input type="text" id="chatData" placeholder="Message" />
    	    <input type="button" value=" Send " id="trig" />
        
       
      
      
      
    </body>
    </html>

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by djr33 View Post
    ... if you can ask a specific question we may be able to help with that.
    Quote Originally Posted by mutanx View Post
    Below is the code. when i try to integrate the sound into chat application. the sound stops working
    This is not a "specific question." It's more like a "code dump."

    As Daniel said, we are not here to do your homework for you. If you find a specific question, and care to take the time to ask it properly, you are welcome to post again.

    Your question is unclear.
    Please provide more information, and be as clear and specific as possible.
    • What do you want to accomplish?
    • What have you already tried?
    • What problems did you encounter (i.e., what did you expect, and what actually happened)?

    Please be sure that you have included all relevant code and/or a link to the page in question. Online tools like codepen or jsfiddle can be quite useful.
    Also consider making a reduced test case to demonstrate your problem.

Similar Threads

  1. Replies: 0
    Last Post: 06-17-2010, 02:57 PM
  2. Chat application
    By kiranpeter in forum JavaScript
    Replies: 0
    Last Post: 06-23-2009, 05:19 AM
  3. Resolved Helps on Ajax Tabs Content Script (v2.2)
    By dd8081 in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 05-03-2009, 03:51 PM
  4. chat application performance issues
    By jackbenimble4 in forum JavaScript
    Replies: 1
    Last Post: 07-21-2008, 09:48 PM
  5. Helps on DD tab menu pls
    By Sin in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 11-14-2005, 07:24 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •