Sorry, may i know what is the problem?

load_data = {'fetch':1};
 $.post('shout.php', load_data,  function(data) {
    var scrolltoh = $('.message_box')[0].scrollHeight;
}, 1000);

$("#shout_message").keypress(function(evt) {
        if(evt.which == 13) {
                var iusername = $('#shout_username').val();
                var imessage = $('#shout_message').val();
                var roomID = $('#room_id').val();
                post_data = {'username':iusername, 'message':imessage, 'roomID':roomID};

                //send data to "shout.php" using jQuery $.post()
                $.post('shout.php', post_data, function(data) {

                    //append data into messagebox with jQuery fade effect!

                    //keep scrolled to bottom of chat!
                    var scrolltoh = $('.message_box')[0].scrollHeight;

                    //reset value of message box

                }).fail(function(err) { 

                //alert HTTP server error

The problem come to this page, shout.php


    //check if its an ajax request, exit if not
    if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {

    if(isset($_POST["message"]) &&  strlen($_POST["message"])>0)

        $username = $_POST["username"];
        $message = $_POST["message"];
        $room_id = $_POST["roomID"];
        $user_ip = $_SERVER['REMOTE_ADDR'];

        if(mysqli_query($sql_con,"INSERT INTO shout_box(user, message, ip_address, room_id) value('$username','$message','$user_ip','$room_id')"))
            $msg_time = date('h:i A M d',time()); // current time
            echo '<div class="shout_msg"><time>'.$msg_time.'</time><span class="username">'.$username.'</span><span class="message">'.$message.'</span></div>';

        mysqli_query($sql_con,"DELETE FROM shout_box WHERE id NOT IN (SELECT * FROM (SELECT id FROM shout_box ORDER BY id DESC LIMIT 0, 10) as sb)");

    else if($_POST["fetch"]==1)
        $room_id = $_POST["roomID"];  //Not working here.
        $results = mysqli_query($sql_con,"SELECT user, message, date_time FROM (select * from shout_box ORDER BY id DESC LIMIT 10) shout_box ORDER BY ASC");
        while($row = mysqli_fetch_array($results))
            $msg_time = date('h:i A M d',strtotime($row["date_time"])); //message posted time
            echo '<div class="shout_msg"><time>'.$msg_time.'</time><span class="username">'.$row["user"].'</span> <span class="message">'.$row["message"].'</span></div>';
        header('HTTP/1.1 500 Are you kiddin me?');

It show the message
Undefined index: roomID in C:\xampp\htdocs\Web\chat\shout.php on line 31

It does work in line 16. What is the problem? thanks for advance


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.