Jump to content

Ajax help needed


pztpenguin

Recommended Posts

Hi, I used this script before to delete contacts from a project I'm working on. So I thought I would use again, but this time I'm having problems. I'm trying to delete a user row from the DB table. The ajax

function deleteUser2(id){
new Ajax.Request('deleteuser025.php', {
parameters: $('idUser'+id).serialize(true),
});
}

function deleteUser2(id){
var pars = 'user_id=' + id ;
var okToRefresh = confirm("Do you really want to delete the User?");
if (okToRefresh)
    {
            setTimeout("location.reload(true);",1000);
            new Ajax.Updater( 'answers-area', 'deleteuser025.php', { method: 'post', parameters: pars } );
    }


} 

The php I'm trying to run it from..

echo"<td class='userlist_field2'><a href='#' onclick='deleteUser2($username93).refresh()'><img src='images/s_trash.png' alt='user delete' /></a></td>";

 

This is just the snippet of where I'm having the problem. When I check the fire fox fox error console it shows the variable as if it where echoed out "it shows the user name" and says its undefined.  I can't figure this one out, any help would be appreciated.

Link to comment
Share on other sites

Okay maybe I should clarify myself. The error I'm getting is..

Error: test08 is not defined //// that is the user name (test08) I'm trying to delete.

Source File: http://******.******.org/**********/index.php?pg=users.php#    Line: 1

 

I made some more changes to the ajax that I had used to delete contacts. The new ajax code..

function deleteUser2(username){
new Ajax.Request('deleteuser025.php', {
parameters: $('username'+username).serialize(true),
});
}

function deleteUser2(username){
var pars = 'username=' + username ;
var okToRefresh = confirm("Do you really want to delete the user?");
if (okToRefresh)
    {
            setTimeout("location.reload(true);",1000);
            new Ajax.Updater( 'answers-area', 'deleteuser025.php', { method: 'post', parameters: pars } );
    }


} 

I'm not for sure If I need that first js function. All my ajax functions is in one file along with the XMLHttpRequest. So I don't think it's that since how it works on the deleting the contacts. The script link is in the head section. This is driving me nuts :wtf: . I'm on the point of just adding a new id index to the db since how that's how the contacts get deleted by the id. I'm going to add the class function I use to call the the user table.

 

function AdminListUsers() {
        global $database;
    echo "<div class='userlist'>";
    echo "<table class='userlist' align=\"left\" cellspacing=\"0\" cellpadding=\"3\">\n";
    
    $q = "SELECT * FROM ".TBL_USERS." ORDER BY username ASC";
    $result = $database->query($q);
    $num_rows = mysql_num_rows($result);
    
    if (!$result) {
    echo "<tr><td>There are no users to list.</td></td>";
    } else {
    
    echo "<tr><td class='userlist_tfield'>Image</td><td class='userlist_tfield'>User Name</td><td class='userlist_tfield'>Email</td><td class='userlist_tfield'>First Name</td><td class='userlist_tfield'>Last Name</td><td class='userlist_tfield'>State</td><td class='userlist_tfield'>last login</td><td class='userlist_tfield'>Join Date</td><td class='userlist_tfield'>Edit</td><td class='userlist_tfield'>Delete</td>";
        for($i=0; $i<$num_rows; $i++){
        $username93 = mysql_result($result,$i,"username");
        $userimg    = mysql_result($result,$i,"img"); 
        $email        = mysql_result($result,$i,"email");
        $firstname    = mysql_result($result,$i,"firstname");
        $lastname    = mysql_result($result,$i,"lastname");
        $state        = mysql_result($result,$i,"state");
        $lastlogin    = mysql_result($result,$i,"lastlogin");
        $day        = mysql_result($result,$i,"day");
        $month        = mysql_result($result,$i,"month");
        $year        = mysql_result($result,$i,"year");
        $noimage = "http://***.***.**.***/****/**/user.png";
        
    echo "<tr><td class='userlist_field'>"; if ($userimg === false) { echo"<img src='/images/user.png'></img>"; } else { echo"<img src='imgsize.php?img=".$userimg."&w=30px$h=30px'></img>"; }   echo "</td><td class='userlist_field2'>$username93</td><td class='userlist_field'>$email</td><td class='userlist_field2'>$firstname</td><td class='userlist_field'>$lastname</td><td class='userlist_field2'>$state</td><td class='userlist_field'>$lastlogin</td><td class='userlist_field2'>$month, $year</td><td class='userlist_field'><a href='#'><img src='images/s_edit.png' alt='user edit' /></a></td><td class='userlist_field2'><a href='#' onclick='deleteUser2($username93).refresh()'><img src='images/s_trash.png' alt='user delete' /></a></td>";
    }
    echo "</tr></table></div>";
}
}

Then I call the class function on the users page by the user.php

$AdminUser->AdminListUsers();

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.