MjM8082 Posted August 3, 2011 Share Posted August 3, 2011 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(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/243656-delete-user-in-mysql/ Share on other sites More sharing options...
phpSensei Posted August 3, 2011 Share Posted August 3, 2011 DELETE FROM `table` WHERE `user_id` = '$id' Quote Link to comment https://forums.phpfreaks.com/topic/243656-delete-user-in-mysql/#findComment-1251065 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.