PHP delete user

delete user information

(1) Specify / delete a single line

A single line is to write the corresponding ID to the delete.php file through GET parameter transmission

(2) Batch delete

Multiple deletion is to pass the corresponding ID to the delete.php page through POST

if(is_array($_POST['id'])){
    $id = join(',',$_POST['id']);
}elseif(is_numeric($_GET['id'])){
    $id = (int)$_GET['id'];
}

 

Knowledge points:

①is_array() determines whether it is an array;

②join() function is an alias of implode() function, which returns a string composed of array elements

<?php  
    $arr = array("hello", "world");  
    $str = join("|", $arr);  
    echo $str; //output hello|word
?>  

 

③is_numeric — Detects whether a variable is a number or numeric character

principle:

The join function changes the id from the multi-select delete into the format of 3, 4, 5,

Finally, the effect of executing the SQL statement for multiple selection and deletion is delete from user where id in(3,4,5);

The effect of the single-select delete statement is delete from user where id in(3);

In this way, the self-adaptation of single-selection and multi-selection is realized

$sql = "delete from user where id in($id)";

 

 

 

(3) If they do not match, the data will be deemed illegal

 

 

【Case】

(1) Delete a single user

               //delete users
		if(is_numeric($_GET['id'])){//Single selection number
		    $id = (int) $_GET['id'];//Convert to integer
		// echo "number";
		}else{
		    echo "Invalid data";
		    exit;
		}
		// $sql = "delete from demo where id in($id)"//Single and double take all
		$sql = "delete from demo where id in($id)";
		$result = mysqli_query($connect,$sql);//Execute delete operation
		// execute delete
	  	$result = mysqli_query($connect,$sql);
		if($result){
		    echo "Delete successful";
		}else{
		    echo "Delete failed";
		}

 (2) To delete users in batches, add a checkbox in front, and pass the id array to the delete function when deleting

 About this function, I will make a summary later

 

 

 

Notice:

①When single-select deletion and editing, you need to use the get method to pass in the id, in order to know the user to be operated;

②When deleting multiple selections, multiple users need to be imported. So you can use the form form and submit the user id using the post method

③ Every page that needs a database needs to be connected to the database once, which can be operated with include

 

 

 

 Reference URL:

http://www.jb51.net/article/62766.htm

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326171428&siteId=291194637