Umaid123 Posted December 24, 2008 Share Posted December 24, 2008 I want to make delete button to delete the record from mysql database using PHP. I have made the button in HTML and apply some formatting as below, but i am not coming up on actual logic, so plz help. $comment = $_POST[txt_comment]; $comment_len = strlen ($comment); $delete = $_POST["del"]; if ( $delete > $comment_len ) { function foo($comment) { unset($comment); } } else { echo ($comment); } <input type="submit" value ="Delete" name = "del"> Quote Link to comment https://forums.phpfreaks.com/topic/138298-how-to-make-delete-button-functional-in-my-guestbook/ Share on other sites More sharing options...
chronister Posted December 24, 2008 Share Posted December 24, 2008 Basically you need to get the ID of post attached to the form. When your code grabs the info from the database, you then need to add a hidden field to the form and have it hold the id of the post. Then when that delete button is hit, you will run a query to delete. <input type="hidden" name="commentId" value="<?php echo $commentId; ?>" /> <input type="submit" value ="Delete" name = "del"> <?php if(isset($_POST['del']) && isset($_POST['commentId'])) { $id = $_POST['commentId']; $query = "DELETE FROM tableName WHERE fieldName = '$id'"; $result = mysql_query($query); } ?> Something like that is what you need to do. You will nee to change things to your actual field and table names, but that is the principle. Nate Quote Link to comment https://forums.phpfreaks.com/topic/138298-how-to-make-delete-button-functional-in-my-guestbook/#findComment-723196 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.