Home>Article>Backend Development> php delete user

php delete user

jacklove
jacklove Original
2018-06-11 23:22:59 3185browse

Delete a User'; // Check for a valid user ID, through GET or POST: if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // From view_users.php $id = $_GET['id']; } elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // Form submission. $id = $_POST['id']; } else { // No valid ID, kill the script. echo '

This page has been accessed in error.

'; exit(); } require ('c.php'); // Check if the form has been submitted: if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_POST['sure'] == 'Yes') { // Delete the record. // Make the query: $q = "DELETE FROM user WHERE user_id=$id LIMIT 1";$r = @mysqli_query ($dbc, $q); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. // Print a message: echo '

The user has been deleted.

';} else { // If the query did not run OK. echo '

The user could not be deleted due to a system error.

'; // Public message. echo '

' . mysqli_error($dbc) . '
Query: ' . $q . '

'; // Debugging message. } } else { // No confirmation of deletion. echo '

The user has NOT been deleted.

';} } else { // Show the form. // Retrieve the user's information: $q = "SELECT CONCAT(last_name, ', ', first_name) FROM user WHERE user_id=$id"; $r = mysqli_query ($dbc, $q); if (mysqli_num_rows($r) == 1) { // Valid user ID, show the form. // Get the user's information: $row = mysqli_fetch_array ($r, MYSQLI_NUM); // Display the record being deleted: echo "

Name: $row[0]

Are you sure you want to delete this user?"; // Create the form: echo '
Yes聽 No
'; } else { // Not a valid user ID. echo '

This page has been accessed in error.

'; } } // End of the main submission conditional. mysqli_close($dbc); ?>

This article explains the related operations of deleting users in PHP. For more information, please pay attention to the PHP Chinese website.

Related recommendations:

MySQL database multi-table operation

MySQL database single table query

Oracle database output input

The above is the detailed content of php delete user. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn