pztpenguin Posted October 19, 2010 Share Posted October 19, 2010 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 https://forums.phpfreaks.com/topic/216308-ajax-help-needed/ Share on other sites More sharing options...
pztpenguin Posted October 23, 2010 Author Share Posted October 23, 2010 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 . 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 https://forums.phpfreaks.com/topic/216308-ajax-help-needed/#findComment-1125653 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.