Jump to content

Recommended Posts

How do I delete a user from my MySQL database? When I click the delete button on the website I want the user to be deleted out of the database.

 

Here is my code for the delete button page...

 

<html xmlns="http://www.w3.org/1999/xhtml">

<!-- the head section -->
<head>
    <title>Update User</title>
    
</head>

<!-- the body section -->
<body>
<h1>Update User</h1>

<?php
//echo $_GET['id'];
if (isset($_POST['btn_update']))
{
	echo "My update stuff goes here";
}
else if (isset($_POST['btn_delete']))
{
	echo "My delete stuff goes here";

}
?>


<form name="my_form" method="post" action="update_user.php">
	User Name: <input type="text" name="user_name"><br />
	First Name: <input type="text" name="first_name"><br />
	Last Name: <input type="text" name="last_name"><br />
	Password: <input type="text" name="pwd"><br />
	Admin: <input type="text" name="is_admin">
	<input type="submit" name="btn_update" value="Update User" />
	<input type="submit" name="btn_delete" value="Delete User" />
</form>

</body>
</html>

 

 

here is the database

<?php
    $dsn = 'mysql:host=localhost;dbname=se266';
    $username = 'se266_user';
    $password = 'pwd';

    try {
        $db = new PDO($dsn, $username, $password);
    } catch (PDOException $e) {
        $error_message = $e->getMessage();
        include('database_error.php');
        exit();
    }
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/243656-delete-user-in-mysql/
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.