steviez Posted February 8, 2007 Share Posted February 8, 2007 Hi, I need the following code to be executed when a user clicks on the delete button: <?php if(!$UsErId) { $redirect = $SITEURL."login.php"; header("Location:$redirect"); } session_start(); if (isset($_SESSION['$UsErId'])) { $sql = "DELETE FROM user WHERE id = '{$_SESSION['$UsErId']}'"; if (mysql_query($sql)) { $redirect = $SITEURL."logout.php"; header("location:$redirect"); } else { echo "Delete failed"; } } ?> How is this done? The button when pressed will delete a user from the database. Thanks Quote Link to comment Share on other sites More sharing options...
papaface Posted February 8, 2007 Share Posted February 8, 2007 something like <?php if (isset($_POST['delete'])) { $delete = $_POST['delete']; if ($delete == "yes") { $sql = "DELETE FROM user WHERE id = '{$_SESSION['$UsErId']}'"; if (mysql_query($sql)) { $redirect = $SITEURL."logout.php"; header("location:$redirect"); } else { echo "Delete failed"; } } else { echo "You chose not to delete the record"; } } ?> <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post"> <input name="delete" type="submit" value="yes" /> <input name="delete" type="submit" value="no" /> </form> I wrote it quite quickly so there may be some minor errors. Quote Link to comment Share on other sites More sharing options...
steviez Posted February 8, 2007 Author Share Posted February 8, 2007 Thank you that worked a treat! i dont suppose anyone could help me with the next problem in this puzzle? When the user is deleted from the database i am wanting all their images, uploads etc to be deleted at the same time. Is this possable and if so how? Thanks Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 8, 2007 Share Posted February 8, 2007 If you have their user id associated with those uploads, just DELETE FROM uploads WHERE userid = '$id' Quote Link to comment Share on other sites More sharing options...
steviez Posted February 8, 2007 Author Share Posted February 8, 2007 I already have one query tho: $sql = "DELETE FROM user WHERE id = '$UsErId'"; how do i make it do two or three more sql querys at once? Quote Link to comment 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.