Jump to content

Trouble Getting Form to Process.


codeboyuk

Recommended Posts

Hi,

 

I posted earlier referring to this issue, but then went away to attempt to resolve it. Anyway - no joy.

 

The problem I am having (I think), is getting the form to process once the user has clicked 'delete'. Basically - nothing happens. I have error reporting switched on, but I'm not receiving any notifications.

 

I based this on a procedural approach, although I've modified it to fit into a class. That seems to be where the problems started - because I had to change the form action attribute (with the procedural approach, it was pointing to a file. With the oo approach I had to change to PHP_SELF).

 

The basics of my approach are as follows:

 

Files used:

 

1/remove_user.php

- calls and initiates the methods and classes.

 

2/userAuthorisationFunctions.php

- stores the classes and methods

- removeUsers() is the method that I am using and calling to do the work here.

 

3/I'm using checkboxes and a while loop to run the SQL data through and populate a table.

 

4/There is one delete button that is designed to delete any number of users that the administrator has 'checked'. Because I only want one occurence of the button, I have placed it just outside of the loop.

 

5/The page is rendering correctly, showing a list of current system users.

 

I originally stored the form opening and closing elements in remove_user.php. However, as I had been having trouble getting it to work, I moved both elements over to be stored within removeUsers()....I could move them back, but as I don't know where the error is, I have left them where they are.

 

I think that the error is likely to be in one of two place:

 

a/ The action attribute.

b/ The loop syntax.

 

Here are the files:

 

remove_user.php

session_start();
$pageTitle = "Remove User";
include("../includes/admin_header.php");
include("../classes/userAuthorisationFunctions.php");
echo '<div class="admin_main_body">';
echo '<br /><br />';
$userManagement = new userManagement();
$userManagement->removeUsers();
echo '<div>';
include("../includes/admin_footer.php");

 

userAuthorisationFunctions.php

 

class userManagement {
   function getUsers() {  
   //To display users. Probably redundant.

   ($GLOBALS["___mysqli_ston"] = mysqli_connect("localhost", "root", "")) or die(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
   ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE practicesite")) or die (((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));

  $query = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM admin ORDER BY username ASC");
  while ($user = mysqli_fetch_assoc($query)) {
  echo '<table><tr><th colspan="1">Username</th><th colspan="1">Email Address</th></tr>';
  echo '<tr class="yellow"><td class="width">' . $user['username'] . '</td><td class="adjacent">' . $user['email'] . '</td></tr>';     
  echo '</table>';
       }
   }
   function removeUsers() {
   //To display users and also allow an administrator to remove users.

($GLOBALS["___mysqli_ston"] = mysqli_connect("localhost", "root", "")) or die(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
   ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE practicesite")) or die (((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));

   //if (isset($_POST['submit'])){
   if(!isset( $_REQUEST['action']) ) {
      $sql = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM admin ORDER BY username ASC");
      while ($user = mysqli_fetch_assoc($sql)) {
       //echo '<table><tr><th colspan="1">Username</th><th colspan="1">Email Address</th><th colspan="1">Delete User</th></tr>';
       //echo '<table><tr>';
       echo '<form id = "photo_del_form" method = "post" action = "htmlentities($_SERVER["PHP_SELF"])">';
       echo '<table>';
       echo '<tr class="yellow"><td class="width">Username</td><td class="adjacent">Email Address</td><td class="adjacent"></td><td class="adjacent"></td></tr>';
       echo '<tr><td>' . $user['username'] . '</td><td class="adjacent">' . $user['email'] . '</td><td class="adjacent"><input type="checkbox" name=' . $user['username'] . '/></td></tr>';     
       echo '</table>';
       echo '<form>';
       echo '<input type="submit" value="Delete Selected User(s)"/>';
       } else if(isset($_REQUEST['action']))
             {
       if (count($_POST) > 0 ) {
       $userDelcount = 0;
       foreach($_POST as $name => $value)
               {
       $query = "DELETE * FROM admin WHERE where username = '$name'";
       echo $query;
       $result = mysqli_query($GLOBALS["___mysqli_ston"], $query);                
       if ($result) {
       echo $result;
       $userDelcount ++;
                   }            
               }
                               }               
               else 
                  if (count($_POST) != $userDelCount )
                       {
                       echo "<p>There was a problem processing your request.Please try again later.</p>";              	 
                       } 
                           else 
                           {
                            echo "<p>The user(s) you selected has/have been deleted.</p>";              	    
                            unset($_REQUEST['action']);
                            echo "<p>Please <a href = '../admin170976/remove_user.php'>click here to continue.</p>";
             	        }
                } else 
                echo "<p>You did not select any users.</p>";
                     //"<p>Please <a href = '../admin170976/remove_user.php'>click here to return.</p>";
       } //End of function.
   } 
}

 

 

Any advice would be really appreciated.

 

Cheers

Link to comment
Share on other sites

Would you mind posting code that doesn't have errors in it? Specifically, it looks like you are missing brackets, and where I would logically add brackets doesn't make sense with your particular code.

 

Specifically, this section at the end of your class, which appears to have an else {} followed immediately by another else {}:

 

				else
				if (count($_POST) != $userDelCount ) {
					echo "<p>There was a problem processing your request.Please try again later.</p>";
				}
			else {
				echo "<p>The user(s) you selected has/have been deleted.</p>";
				unset($_REQUEST['action']);
				echo "<p>Please <a href = '../admin170976/remove_user.php'>click here to continue.</p>";
			}
		} else
		echo "<p>You did not select any users.</p>";

 

I know that technically you don't have to use brackets around if/else if/else if they only have one line (for example, the first "else" in the code above), but it's significantly easier to read your code if you include them, especially when you are dealing with multiple nested if/else if/else statements.

Link to comment
Share on other sites

Would you mind posting code that doesn't have errors in it? Specifically, it looks like you are missing brackets, and where I would logically add brackets doesn't make sense with your particular code.

 

Specifically, this section at the end of your class, which appears to have an else {} followed immediately by another else {}:

 

				else
				if (count($_POST) != $userDelCount ) {
					echo "<p>There was a problem processing your request.Please try again later.</p>";
				}
			else {
				echo "<p>The user(s) you selected has/have been deleted.</p>";
				unset($_REQUEST['action']);
				echo "<p>Please <a href = '../admin170976/remove_user.php'>click here to continue.</p>";
			}
		} else
		echo "<p>You did not select any users.</p>";

 

I know that technically you don't have to use brackets around if/else if/else if they only have one line (for example, the first "else" in the code above), but it's significantly easier to read your code if you include them, especially when you are dealing with multiple nested if/else if/else statements.

 

Hi Ben

 

Sorry about the missing tag! I edited the script slightly before posting it in order to make it more easily understood, but I seem to have removed the closing while loop bracket (this should have been placed just after the closing table tag). I notice that I failed to close the form tag and I'd also forgotten to remove the 'error checking' lines: if ($result) {

echo $result;

$userDelcount ++;

}

 

I made a few mistakes. Clearly I was having a bad day! :)

 

I agree with you about tags. They add clarity to a script. If I've missed any it will usually be unintentional (unless I'm modifying someone else's script).

 

I attach the new formats of the same scripts. They are slightly different to yesterday: I've moved the form elements out of removeUsers() and into remove_user.php. This is how I had it originally, and I think that it looks neater. I've also cleaned up the code - removing any needless/redundant lines.

 

I'm still getting erros - but maybe you can see where the problem lies....Hopefully anyway!

 

remove_user.php

 

 
session_start();
$pageTitle = "Remove User";
include("../includes/admin_header.php");
include("../classes/userAuthorisationFunctions.php");
echo '<div class="admin_main_body">';
echo '<br /><br />';
$userManagement = new userManagement();

<form name="userList" action="<?php htmlentities($_SERVER["PHP_SELF"]) ?>" method="post"> 

$userManagement->removeUsers();
echo '<form>';
echo '<div>';
include("../includes/admin_footer.php");

 

userAuthorisationFunctions.php

 


class userManagement {
           function getUsers() {
   ($GLOBALS["___mysqli_ston"] = mysqli_connect("localhost", "root", "")) or die(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
   ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE practicesite")) or die (((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));

  $query = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM admin ORDER BY username ASC");
  while ($user = mysqli_fetch_assoc($query)) {
  echo '<table><tr><th colspan="1">Username</th><th colspan="1">Email Address</th></tr>';
  echo '<tr class="yellow"><td class="width">' . $user['username'] . '</td><td class="adjacent">' . $user['email'] . '</td></tr>';     
  echo '</table>';
       }
   }
   function removeUsers() {
   ($GLOBALS["___mysqli_ston"] = mysqli_connect("localhost", "root", "")) or die(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
   ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE practicesite")) or die (((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));

   if(!isset( $_REQUEST['action']) ) {
      $sql = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM admin ORDER BY username ASC");
      while ($user = mysqli_fetch_assoc($sql)) {
       echo '<table>';
       echo '<tr class="yellow"><td class="width">Username</td><td class="adjacent">Email Address</td><td class="adjacent"></td><td class="adjacent"></td></tr>';
       echo '<tr><td>' . $user['username'] . '</td><td class="adjacent">' . $user['email'] . '</td><td class="adjacent"><input type="checkbox" name=' . $user['username'] . '/></td></tr>';     
       echo '</table>';
           }
       echo '<input type="submit" value="Delete Selected User(s)"/>';
       } else if(isset($_REQUEST['action']))
             {
       if (count($_POST) > 0 ) {
       $userDelcount = 0;
       foreach($_POST as $name => $value)
               {
       $query = "DELETE * FROM admin WHERE where username = '$name'";
       if (@mysqli_query($GLOBALS["___mysqli_ston"], $query));
                   {
       $userDelcount ++;
                   }            
               }
                               }               
               else 
                  if (count($_POST) != $userDelCount )
                       {
                       echo "<p>There was a problem processing your request.Please try again later.</p>";              	 
                       } 
                           else 
                           {
                            echo "<p>The user(s) you selected has/have been deleted.</p>";              	    
                            unset($_REQUEST['action']);
                            echo "<p>Please <a href = '../admin170976/remove_user.php'>click here to continue.</p>";
             	        }
                } else 
                echo "<p>You did not select any users.</p>";
                     //"<p>Please <a href = '../admin170976/remove_user.php'>click here to return.</p>";
               }
   }
//$register = new Register();

 

Thanks a lot!!

Link to comment
Share on other sites

You still have significant issues at the end of your code sample. Like I said previously, I'm not sure which "if" statement the two "else"s go with.

 

else 
                  if (count($_POST) != $userDelCount )
                       {
                       echo "<p>There was a problem processing your request.Please try again later.</p>";                       
                       } 
                           else 
                           {
                            echo "<p>The user(s) you selected has/have been deleted.</p>";                         
                            unset($_REQUEST['action']);
                            echo "<p>Please <a href = '../admin170976/remove_user.php'>click here to continue.</p>";
                       }
                } else 
                echo "<p>You did not select any users.</p>";
                     //"<p>Please <a href = '../admin170976/remove_user.php'>click here to return.</p>";
               }

 

Ignoring that for now... would it be possible to get a mySql dump of that specific table in your database that you are working with? I was trying to work without it, but since so much is dependent on it, that would be helpful.

Link to comment
Share on other sites

You still have significant issues at the end of your code sample. Like I said previously, I'm not sure which "if" statement the two "else"s go with.

 

else 
                  if (count($_POST) != $userDelCount )
                       {
                       echo "<p>There was a problem processing your request.Please try again later.</p>";                       
                       } 
                           else 
                           {
                            echo "<p>The user(s) you selected has/have been deleted.</p>";                         
                            unset($_REQUEST['action']);
                            echo "<p>Please <a href = '../admin170976/remove_user.php'>click here to continue.</p>";
                       }
                } else 
                echo "<p>You did not select any users.</p>";
                     //"<p>Please <a href = '../admin170976/remove_user.php'>click here to return.</p>";
               }

 

Ignoring that for now... would it be possible to get a mySql dump of that specific table in your database that you are working with? I was trying to work without it, but since so much is dependent on it, that would be helpful.

 

 

Hi

 

Here's the SQL Schema:

 

CREATE TABLE IF NOT EXISTS `admin` (

`admin_id` int(8) unsigned NOT NULL AUTO_INCREMENT,

`username` varchar(20) NOT NULL,

`email` varchar(40) NOT NULL,

`password` varchar(40) NOT NULL,

PRIMARY KEY (`admin_id`),

UNIQUE KEY `username` (`username`,`email`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=28 ;

 

INSERT INTO `admin` (`admin_id`, `username`, `email`, `password`) VALUES

(1, 'Testing', 'test@test.com', '7288edd0fc3ffcbe93a0cf06e3568e28521687bc'),

(2, 'Test2', 'testing3@testing.com', 'dc724af18fbdd4e59189f5fe768a5f8311527050'),

(3, 'Wilhelm', 'admin@blooter.com', 'dc724af18fbdd4e59189f5fe768a5f8311527050'),

(4, 'TestAgain', 'Testing@testing3.com', 'dc724af18fbdd4e59189f5fe768a5f8311527050'),

(5, 'WillyWonka', 'will@will.com', 'dc724af18fbdd4e59189f5fe768a5f8311527050'),

(6, 'Spiderman', 'Spiderman@spidey.com', 'dc724af18fbdd4e59189f5fe768a5f8311527050'),

(7, 'Superman', 'Clarke@Krypton.com', 'dc724af18fbdd4e59189f5fe768a5f8311527050');

 

 

I've included the class file again with comments to accompany the closing conditionals....Does it make any sense??

 

class userManagement {
           function getUsers() {
   ($GLOBALS["___mysqli_ston"] = mysqli_connect("localhost", "root", "")) or die(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
   ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE practicesite")) or die (((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));

  $query = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM admin ORDER BY username ASC");
  while ($user = mysqli_fetch_assoc($query)) {
  echo '<table><tr><th colspan="1">Username</th><th colspan="1">Email Address</th></tr>';
  echo '<tr class="yellow"><td class="width">' . $user['username'] . '</td><td class="adjacent">' . $user['email'] . '</td></tr>';     
  echo '</table>';
       }
   }
   function removeUsers() {
   ($GLOBALS["___mysqli_ston"] = mysqli_connect("localhost", "root", "")) or die(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
   ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE practicesite")) or die (((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));

   //if (isset($_POST['submit'])){
   if(!isset( $_REQUEST['action']) ) {
      $sql = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM admin ORDER BY username ASC");
      while ($user = mysqli_fetch_assoc($sql)) {
       echo '<table>';
       echo '<tr class="yellow"><td class="width">Username</td><td class="adjacent">Email Address</td><td class="adjacent"></td><td class="adjacent"></td></tr>';
       echo '<tr><td>' . $user['username'] . '</td><td class="adjacent">' . $user['email'] . '</td><td class="adjacent"><input type="checkbox" name=' . $user['username'] . '/></td></tr>';     
       echo '</table>';
           }
       echo '<input type="submit" value="Delete Selected User(s)"/>';
       } else if(isset($_REQUEST['action']))
             {
       if (count($_POST) > 0 ) {
       $userDelcount = 0; //Sets counter to 0....Each time a delete request is passed to the database, the value is incremented by 1. 
       foreach($_POST as $name => $value)
               {
       //echo "$name";        
       $query = "DELETE * FROM admin WHERE where username = '$name'";
       //$result = mysqli_query($GLOBALS["___mysqli_ston"], $query);                
       if (@mysqli_query($GLOBALS["___mysqli_ston"], $query)); //If a query was received.
                   {
       $userDelcount ++; //Increment the $userDelcount variable by 1.
                   }            
               } //closes foreach loop
                               } //Closes if (count) condition.               
               else if (count($_POST) != $userDelCount ) //If the number of users, passed by the form, does not equal the value of the counted users passed to the userDelcount variable, print error.  
                       {
                       echo "<p>There was a problem processing your request.Please try again later.</p>";              	 
                       } 
                           else //if users were successfully deleted.... 
                           {
                            echo "<p>The user(s) you selected has/have been deleted.</p>";              	    
                            unset($_REQUEST['action']);
                            echo "<p>Please <a href = '../admin170976/remove_user.php'>click here to continue.</p>";
             	        }
                } else  //This line should display if $_REQUEST['action'] was not sent by the form when the delete button was activated, but no values were received i.e. no users were checked/selected..
                echo "<p>You did not select any users.</p>";
                     //"<p>Please <a href = '../admin170976/remove_user.php'>click here to return.</p>";
               }
   }

Link to comment
Share on other sites

Well, I should be able to help you get started...

 

1)

First off, your form only gets processed when "isset($_REQUEST['action'])" returns true. $_REQUEST, as far as I understand it, holds data from $_POST, $_GET, or cookies, and you don't ever set $action anywhere in your script. Either you need to add an element within your form that is named "action" or you need to set the action="" attribute on your form to redirect to the same page, plus add "?action" in the URL (which will set $_GET['action'].) For example:

 

<form name="userList" action="<?php htmlentities($_SERVER["PHP_SELF"]) ?>?action" method="post">

 

2)

Secondly, the way you create your checkboxes will result in users never being deleted. You've forgotten to add quotes around the value of the checkbox, resulting in something like this, which includes the "/" in the name (and thus, also in your delete query):

 

<input type="checkbox" name=WillyWonka/>

 

3)

Just so you are aware... You have a logic error within your removeUsers() function. Simplified, your code looks like this:

 

if (!isset( $_REQUEST['action']) ) 
{
  ...
} 
else if (isset($_REQUEST['action'])) 
{
  ...
} 
else  
{
  ...
}

That "else" will never occur. Either $_REQUEST['action'] is set, or it isn't set -- there isn't any third option.

Link to comment
Share on other sites

Well, I should be able to help you get started...

 

1)

First off, your form only gets processed when "isset($_REQUEST['action'])" returns true. $_REQUEST, as far as I understand it, holds data from $_POST, $_GET, or cookies, and you don't ever set $action anywhere in your script. Either you need to add an element within your form that is named "action" or you need to set the action="" attribute on your form to redirect to the same page, plus add "?action" in the URL (which will set $_GET['action'].) For example:

 

<form name="userList" action="<?php htmlentities($_SERVER["PHP_SELF"]) ?>?action" method="post">

 

2)

Secondly, the way you create your checkboxes will result in users never being deleted. You've forgotten to add quotes around the value of the checkbox, resulting in something like this, which includes the "/" in the name (and thus, also in your delete query):

 

<input type="checkbox" name=WillyWonka/>

 

3)

Just so you are aware... You have a logic error within your removeUsers() function. Simplified, your code looks like this:

 

if (!isset( $_REQUEST['action']) ) 
{
  ...
} 
else if (isset($_REQUEST['action'])) 
{
  ...
} 
else  
{
  ...
}

That "else" will never occur. Either $_REQUEST['action'] is set, or it isn't set -- there isn't any third option.

 

Hi Ben....thanks - you have given me great help here....

I was unsure exactly what the $_REQUEST action actually achieved. I came to the conclusion (clearly misguided) that it was subtly different to $_POST/$_GET in that it didn't need to correspond to a "name" attribute being set. I thought that instead it was just checking to see whether the form itself had been actioned (i.e. the "action" attribute had been called/REQUESTED). But it seems I was wrong.

I've just seen that you have also replied to my other post relating to the confusion I was having regarding the action attribute and how I should set it in this instance.....It looks like that is the fundamental problem. But I reckon I can sort it now :)

 

Yea - the logic isn't brilliant! It was never my strong point...I just try to battle on through until I get the desired result....I think that part of the problem is that I relied on a third party script as a framework to this script. So, if the script I was using to model this code on was flawed, then as a consequence, this script was going to be flawed....

 

I'm gonna go back through your pointers and implement the changes to the script tomorrow....

 

I'll keep you posted :)

 

Thanks again!!! If you didn't live 5 thousand miles away, I'd buy you a pint!

Link to comment
Share on other sites

Hi Ben....thanks - you have given me great help here....

I was unsure exactly what the $_REQUEST action actually achieved. I came to the conclusion (clearly misguided) that it was subtly different to $_POST/$_GET in that it didn't need to correspond to a "name" attribute being set. I thought that instead it was just checking to see whether the form itself had been actioned (i.e. the "action" attribute had been called/REQUESTED). But it seems I was wrong.

I've just seen that you have also replied to my other post relating to the confusion I was having regarding the action attribute and how I should set it in this instance.....It looks like that is the fundamental problem. But I reckon I can sort it now :)

 

Yea - the logic isn't brilliant! It was never my strong point...I just try to battle on through until I get the desired result....I think that part of the problem is that I relied on a third party script as a framework to this script. So, if the script I was using to model this code on was flawed, then as a consequence, this script was going to be flawed....

 

I'm gonna go back through your pointers and implement the changes to the script tomorrow....

 

I'll keep you posted :)

 

Thanks again!!! If you didn't live 5 thousand miles away, I'd buy you a pint!

 

I've successfully created the remove_user function.

 

I changed the original scripts somewhat. There was a lot of messy noise in it. I managed to find a good tutorial and used that to create this one successfully...

 

Here are the files in case anybody wants to use the class or modify it. Clearly it can be improved, but it isn't too bad as a beginners attempt at a basic OO...

 

remove_user.php

 

 
session_start();
$pageTitle = "Remove User";
include("../includes/admin_header.php");
include("../classes/userAuthorisationFunctions.php");
echo '<div class="admin_main_body">';
echo '<div class ="admin_main_body" id="listing">';
echo '<br /><br />';
$userManagement = new userManagement();

<form name="userList" action="<?php htmlentities($_SERVER["PHP_SELF"]) ?>" method="post">

$userManagement->showUsers();
$userManagement->removeUsers();
echo '<div>';
echo '<div>';
include("../includes/admin_footer.php");

 

user_Authorisation.php

 

class userManagement {

      function removeUsers() {


                   ($GLOBALS["___mysqli_ston"] = mysqli_connect("localhost", "root", "")) or die(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
                   ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE practicesite")) or die (((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));

                   if(isset($_POST['delete'])) // from button name="delete"
                {
                   $checkbox = $_POST['checkbox']; //from name="checkbox[]"
                   $countCheck = count($_POST['checkbox']); 
                   for($i=0;$i<$countCheck;$i++)
                           {
                   $del_id  = $checkbox[$i];
                   $query = "DELETE FROM admin WHERE admin_id = $del_id";
                   $result = @mysqli_query($GLOBALS["___mysqli_ston"], $query);
                           }
		        if($result)
	                    {	
                   header('Location: admin_index.php');
		                }
		        else
		                {
                   echo "Error: form not processed";
		                }
                } else {
                   echo "The form could not be processed";
                   }

               }

   function showUsers() {


                   ($GLOBALS["___mysqli_ston"] = mysqli_connect("localhost", "root", "")) or die(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
                   ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE practicesite")) or die (((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));

                   $query = "SELECT admin_id, username, email FROM admin";
                   $result = @mysqli_query($GLOBALS["___mysqli_ston"], $query);
                   if ($result) {
                   echo "<table cellspacing='0' cellpadding='10'>";
                   echo "<tr><th colspan='4'>List of Current Users</th></tr>";
                   echo "<tr><th>Username</th><th>Email Address</th><th>Select Users</th></tr>";
                   while ($row = $result->fetch_object()) {
                   $email = $row->email;
                   $username = $row->username;
                   $id = $row->admin_id;
                   echo "<tr><td>$username</td><td>$email</td><td><input type='checkbox' name='checkbox[]' id='checkbox[]' value=$id /></td></tr>";
                                                           }
                   echo "</table>";
                   echo "<p><input id='delete' type='submit' class='button' name='delete' value='Delete Selected Users'/></p></form>";
                               } else {
                   echo "The user list could not be displayed due to a technical error. Please consult the administrator.";
                                       }
                       }
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...