How do i make delete button work?
-
I am trying to make a delete button but it doesn't work. $interogare = "SELECT * FROM comments JOIN users ON users.user_id = comments.user_id WHERE movie_id='$movie_id' ORDER BY date_posted DESC"; $result = mysqli_query($dbc, $interogare) or die(mysqli_error($dbc)); while($rand = mysqli_fetch_assoc($result)) { echo '<a href="film.php?com='.$rand['comment_id'].'">Delete</a>'; if(isset($_GET['com'])) { $haidi = mysqli_real_escape_string($dbc,$_GET['com']); $sql_del = "DELETE FROM comments WHERE comment_id = '$haidi'"; mysqli_query($dbc,$sql_del); header('location: film.php?id='.$_GET['id'].''); exit(); } } When i click the delete link it takes me to film.php?com='.$rand['comment_id'].' page but nothing happens,it should delete my comment and take me back to the page where the comment was.Can someone please help me figure this out ?
-
Answer:
does this work? <?php $query = " SELECT * FROM comments JOIN users ON users.user_id = comments.user_id WHERE movie_id=" . $movie_id . " ORDER BY date_posted DESC"; $result = mysqli_query($dbc, $query) or die(mysqli_error($dbc)); if (isset($_GET)) { $getData = $_GET; } while ($rand = mysqli_fetch_assoc($result)) { echo '<a href="film.php?com=' . $rand['comment_id'] . '">Delete</a>'; if (isset($getData) && $getData['com']) { $id = mysqli_real_escape_string($dbc, $getData['com']); $query = " DELETE FROM comments WHERE comment_id=" . $id; $result = mysqli_query($dbc, $query); if($result) { header('location: film.php?id=' . $id . ''); } exit(); } } i would rather grab the post once, and then make sure we are passing the same object around, so i set GET to a var. then, i didnt like the way the ids were being set in the query, because it wasnt as easy to see. then i got down to the way you were creating the header, and it looked like you were passing the id from some GET data, instead of the id you just extracted and set to a varibale, see above..., or was that your intention to use $_GET['id'] for that actually instead? also, you might need to pass your data link in the mysqli_real_escape_string() method
Andrew at Stack Overflow Visit the source
Related Q & A:
- How can I use a button to retrieve a phone 'number' from contacts?Best solution by Stack Overflow
- How do I get PayPal button onto my myspace?Best solution by answers.yahoo.com
- How do I make my VCR/DVD work with my TiVo?Best solution by Yahoo! Answers
- How do I put a button on Myspace?Best solution by Yahoo! Answers
- How can I make my brain work faster?Best solution by mensfitness.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.