Jump to content

Was following tutorial


almightyegg

Recommended Posts

but when it came to testing it....I got nothing

 

I am trying to make a chatroom using 3 pages...

 

index.php - where the data is displayed

request.php - whereI select the data from database I need

ajax.js - which is meant to access request.php every 10 milliseconds, and pull the stuff through into index.php

 

at the moment I have an incling that it might be retrieving the variable in the link request.php?room=$room (room being which chat room it is in index.php?room=$room)

 

index.php

<?
include 'db.php'; // Connect to DB
$email = $_COOKIE['email']; 
$password = $_COOKIE['password']; 
if((!$email) || (!$password)){ 
echo "There was an error in your details.<br />"; 
include 'http://www.lordoftheabyss.com/index.php'; 
exit(); 
}else{
$sql = mysql_query("SELECT * FROM users WHERE email='$email'");
$mem = mysql_fetch_array($sql);

$que = mysql_query("SELECT * FROM quests") or die(mysql_error());
$quest = mysql_fetch_array($que);
?>
<!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>
<script type="text/javascript" language="javascript" src="ajax.js"></script>
<link rel="stylesheet" href="http://www.lordoftheabyss.com/layout/default.css"> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<?
$room = $_GET['room'];
?>
<title><? echo $room; ?></title>
</head>

<body bgcolor=black>
<center>
<?
include 'links.php';
?>
</center>
<table border="0" width="1000" cellpadding="6" cellspacing="5">
<tr>
  <td width="200" valign="bottom"><? include 'icons.php'; ?></td>
  <th width="650" bgcolor="#212121"><center><? echo $room; ?></center></th>
  <td width="200" rowspan="2" valign="top" bgcolor="#212121"><left><? include 'links2.php'; ?></left></td>
</tr>
<tr>
  <td width="200" valign="top"><? include 'panel.php'; ?></td>
  <td width="650" bgcolor="#000000" valign="top">

<div id="countPosts" style="height: 300px; width: 500px; overflow: auto; background-color: #CCCCCC; border: 1px solid #555555;"></div>

</td>
</table>
<center>
<?
include 'links.php';
?>
</center>
<?
}
?>
</body>
</html>

 

request.php

<?
include 'db.php';

$blah = mysql_query("SELECT * FROM chat WHERE room = '$room' ORDER BY id DESC LIMIT 20") or die(mysql_error());
while($chat = mysql_fetch_array($blah)){
echo "$chat[message]<br>";
}

?>

 

ajax.js

    function createRequestObject() { 
     
        var req; 
     
        if(window.XMLHttpRequest){ 
            // Firefox, Safari, Opera... 
            req = new XMLHttpRequest(); 
        } else if(window.ActiveXObject) { 
            // Internet Explorer 5+ 
            req = new ActiveXObject("Microsoft.XMLHTTP"); 
        } else { 
            // There is an error creating the object, 
            // just as an old browser is being used. 
            alert('There was a problem creating the XMLHttpRequest object'); 
        } 
     
        return req; 
     
    } 
     
    // Make the XMLHttpRequest object 
    var http = createRequestObject();

function sendRequest(request) { 
         
        // Open PHP script for requests 
var room = gup('room');
var url = 'request.php?room=' + room;
        http.open('get', 'url'); 
        http.onreadystatechange = handleResponse; 
        http.send(null); 
     
    } 
     
    function handleResponse() { 
     
        if(http.readyState == 4 && http.status == 200){ 
     
            // Text returned FROM PHP script 
            var response = http.responseText; 
     
            if(response) { 
                // UPDATE ajaxTest content 
                document.getElementById("countPosts").innerHTML = response; 
                setTimeout(countPosts,20); 
            } 
     
        } 
    } 

    function countPosts() { 
        sendRequest('countPosts'); 
    }

 

anything put forward would be greatly appreciated

Link to comment
Share on other sites

changed it a bit, there is only 1 room now so it doesn't send the $room to request.php anymore....yet it still doesn't work!!

 

index.php -

This is the only relevant code

<div id="show()" style="height: 300px; width: 500px; overflow: auto; background-color: #CCCCCC; border: 1px solid #555555;"></div>

 

request.php -

<?
include 'db.php';

$blah = mysql_query("SELECT * FROM chat ORDER BY id DESC LIMIT 20") or die(mysql_error());
while($chat = mysql_fetch_array($blah)){
echo "$chat[message]<br>";
}

?>

 

ajax.js -

    function createRequestObject() { 
     
        var req; 
     
        if(window.XMLHttpRequest){ 
            // Firefox, Safari, Opera... 
            req = new XMLHttpRequest(); 
        } else if(window.ActiveXObject) { 
            // Internet Explorer 5+ 
            req = new ActiveXObject("Microsoft.XMLHTTP"); 
        } else { 
            // There is an error creating the object, 
            // just as an old browser is being used. 
            alert('There was a problem creating the XMLHttpRequest object'); 
        } 
     
        return req; 
     
    } 
     
    // Make the XMLHttpRequest object 
    var http = createRequestObject();

function sendRequest() { 
        http.open('get', 'request.php'); 
        http.onreadystatechange = handleResponse; 
        http.send(null); 
     
    } 

    } 

    function show() { 
        sendRequest('show'); 
    }

    function handleResponse() { 
     
        if(http.readyState == 4 && http.status == 200){ 
     
            // Text returned FROM PHP script 
            var response = http.responseText; 
     
            if(response) { 
                // UPDATE ajaxTest content 
                document.getElementById("show").innerHTML = response; 
                setTimeout(show,20); 
	alert(OMG);
            } 
     
        } 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.