SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ajax not loading

    Hi for some reason when i click the button to submit my form nothing happenes does anyone know why?

    Code:
    <?php
    include "../remotedatabase.php";
    $loggeduser= "admin";
    ?>
    <<<JS
    <script language="javascript" type="text/javascript">
    <!--
    //Browser Support Code
    function ajaxFunction(){
    var ajaxRequest; // The variable that makes Ajax possible!
    
    try{
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
    } catch (e){
    // Internet Explorer Browsers
    try{
    ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try{
    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e){
    // Something went wrong
    alert("Your browser broke!");
    return false;
    }
    }
    }
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
    if(ajaxRequest.readyState == 4){
    var ajaxDisplay = document.getElementById('ajaxDiv');
    ajaxDisplay.innerHTML = ajaxRequest.responseText;
    }
    }
    var username = document.getElementById('username').value;
    var userlevel = document.getElementById('userlevel').value;
    var jloggeduser = '$loggeduser';
    var queryString = "username=" + username + "&userlevel=" + userlevel + "&loggeduser=" + jloggeduser;
    ajaxRequest.open("POST", "startpage.php" , true);
    ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
    ajaxRequest.send(queryString)
    ajaxRequest.send(null);
    }
    //-->
    </script>
    JS;
    
    
    <?php
    $query23 = mysql_query("SELECT * FROM member WHERE UserName='$loggeduser' ")
    or die("Could not insert data because ".mysql_error());
    $qry23 = mysql_fetch_array( $query23 );
    
    if ( $qry23[MemberType] == "5" ||  $qry23[MemberType] == "4" ||  $qry23[MemberType] == "3" ) {
    ?>
    <form name=myForm method=post>
    <b>UserName:</b> <select id=userlevel>
    <?php
    if ( $qry23[MemberType] == "5" ) {
    ?>
    <option value=>SELECT USERNAME</option>
    <?php
    $result = mysql_db_query($dbname, "SELECT * FROM member WHERE MemberType = '1' or MemberType = '2' or MemberType = '3' or MemberType = '4'  order by username asc ");
    if (mysql_num_rows($result)) {
       while ($qry = mysql_fetch_array($result)) {
    ?>
    <option value=<?= $qry[UserName] ?>><?= $qry[UserName] ?></option>
    <?php
    }
    }
    }
    ?>
    <?php
    if ( $qry23[MemberType] == "4" ) {
    ?>
    <option value=>SELECT USERNAME</option>
    <?php
    $result = mysql_db_query($dbname, "SELECT * FROM member WHERE MemberType = '1' or MemberType = '2' or MemberType = '3'  order by username asc ");
    if (mysql_num_rows($result)) {
       while ($qry = mysql_fetch_array($result)) {
    ?>
    <option value=<?= $qry[UserName] ?>><?= $qry[UserName] ?></option>
    <?php
    }
    }
    }
    ?>
    <?php
    if ( $qry23[MemberType] == "3" ) {
    ?>
    <option value=>SELECT USERNAME</option>
    <?php
    $result = mysql_db_query($dbname, "SELECT * FROM member WHERE MemberType = '1'  order by username asc ");
    if (mysql_num_rows($result)) {
       while ($qry = mysql_fetch_array($result)) {
    ?>
    <option value=<?= $qry[UserName] ?>><?= $qry[UserName] ?></option>
    <?php
    }
    }
    }
    ?>
    </select>
    <b>UserLevel:</b> <select id=userlevel>
    <?php
    if ( $qry23[MemberType] == "5" ) {
    ?>
    
    <option value=moderator>Moderator</option>
    <option value=seniormoderator>Senior Moderator</option>
    <option value=administrator>Administrator</option>
    <?php
    }
    ?>
    <?php
    if ( $qry23[MemberType] == "4" ) {
    ?>
    
    <option value=moderator>Moderator</option>
    <option value=seniormoderator>Senior Moderator</option>
    <?php
    }
    ?>
    <?php
    if ( $qry23[MemberType] == "3" ) {
    ?>
    
    <option value=moderator>Moderator</option>
    <?php
    }
    ?>
    </select>
    <input type=button onclick=ajaxFunction() value=Update User />
    </form>
    <div id=ajaxDiv>
    
    <?php
    }
    $result = mysql_db_query($dbname, "SELECT * FROM member WHERE MemberType = '5' or MemberType = '4' order by username asc ");
    echo "<b>Administrators:</b><br>";
    if (mysql_num_rows($result)) {
       while ($qry = mysql_fetch_array($result)) {
    
    $query2 = mysql_query("SELECT * FROM member WHERE UserName='$qry[UserName]' ")
    or die("Could not insert data because ".mysql_error());
    $qry2 = mysql_fetch_array( $query2 );
    
    $query4 = mysql_query("SELECT * FROM onlineusers WHERE UserName='$qry[UserName]' ")
    or die("Could not insert data because ".mysql_error());
    $qry4 = mysql_fetch_array( $query4 );
    
    $query3 = mysql_query("SELECT * FROM room WHERE RoomID='$qry4[RoomID]' ")
    or die("Could not insert data because ".mysql_error());
    $qry3 = mysql_fetch_array( $query3 );
    
    if (mysql_num_rows($query4) == 0) {
    $status = "Offline";
    }
    else
    {
    $status = "$qry3[RoomName]";
    }
    echo "<img src=../images/icons/admin.png> <a href='../profile/$qry2[UserName]' target='_parent'>$qry2[UserName]</a> ($status)";
    if ( $qry23[MemberType] == "5" )
    {
    echo "<a href='removemoderator.php?username=$qry2[UserName]'> [Remove]</a>";
    }
    ?>
    <br>
    <?php
    }
    }
    
    $result = mysql_db_query($dbname, "SELECT * FROM member WHERE MemberType = '3' order by username asc ");
    echo "<br><b>Senior Moderators:</b><br>";
    if (mysql_num_rows($result)) {
       while ($qry = mysql_fetch_array($result)) {
    
    $query2 = mysql_query("SELECT * FROM member WHERE UserName='$qry[UserName]' ")
    or die("Could not insert data because ".mysql_error());
    $qry2 = mysql_fetch_array( $query2 );
    
    $query4 = mysql_query("SELECT * FROM onlineusers WHERE UserName='$qry[UserName]' ")
    or die("Could not insert data because ".mysql_error());
    $qry4 = mysql_fetch_array( $query4 );
    
    $query3 = mysql_query("SELECT * FROM room WHERE RoomID='$qry4[RoomID]' ")
    or die("Could not insert data because ".mysql_error());
    $qry3 = mysql_fetch_array( $query3 );
    
    if (mysql_num_rows($query4) == 0) {
    $status = "Offline";
    }
    else
    {
    $status = "$qry3[RoomName]";
    }
    echo "<img src=../images/icons/srmod.png> <a href='../profile/$qry2[UserName]' target='_parent'>$qry2[UserName]</a> ($status)";
    if ( $qry23[MemberType] == "5" ||  $qry23[MemberType] == "4" )
    {
    echo "<a href='removemoderator.php?username=$qry2[UserName]'> [Remove]</a>";
    }
    ?>
    <br>
    <?php
    }
    }
    
    $result = mysql_db_query($dbname, "SELECT * FROM member WHERE MemberType = '2' order by username asc ");
    echo "<br><b>Moderators:</b><br>";
    if (mysql_num_rows($result)) {
       while ($qry = mysql_fetch_array($result)) {
    
    $query2 = mysql_query("SELECT * FROM member WHERE UserName='$qry[UserName]' ")
    or die("Could not insert data because ".mysql_error());
    $qry2 = mysql_fetch_array( $query2 );
    
    $query4 = mysql_query("SELECT * FROM onlineusers WHERE UserName='$qry[UserName]' ")
    or die("Could not insert data because ".mysql_error());
    $qry4 = mysql_fetch_array( $query4 );
    
    $query3 = mysql_query("SELECT * FROM room WHERE RoomID='$qry4[RoomID]' ")
    or die("Could not insert data because ".mysql_error());
    $qry3 = mysql_fetch_array( $query3 );
    
    if (mysql_num_rows($query4) == 0) {
    $status = "Offline";
    }
    else
    {
    $status = "$qry3[RoomName]";
    }
    echo "<img src=../images/icons/moderator.png> <a href='../profile/$qry2[UserName]' target='_parent'>$qry2[UserName]</a> ($status)";
    if ( $qry23[MemberType] == "5" ||  $qry23[MemberType] == "4" ||  $qry23[MemberType] == "3" )
    {
    echo "<a href='removemoderator.php?username=$qry2[UserName]'> [Remove]</a>";
    }
    ?>
    <br>
    <?php
    }
    }
    ?>
    
    </div>
    Animated Chatrooms - www.121chatrooms.net

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    It can be quite tricky for any of us to set up a database/server environment that's the same as yours.

    Please post a link to a test page that demonstrates the problem.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •