Hello.
There is an html table in admin page, with head columns (POST ID | POST TITLE | POST AUTHOR | ACTION).
And in each row, will contain a post id, a post title, a post author that gets from database.
And in the Action column, there is a "delete" word that is a link with href="#" for now.
I want the script when i click on the delete word in each rows, erase that row of data from the table of the database and from the html table.
I don't know how should i do that. Just need guidance to understand what i can do for that, thank you.
Niloofar24
15
Posting Whiz
Recommended Answers
Jump to PostTry modify your delete-action.php into:
<?php $servername = "localhost"; $dbname = "mydbname"; $dbusername = "mydbusername"; $dbpassword = "mydbpassword"; try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $dbusername, $dbpassword); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $id=$_GET['id']; $sql = "DELETE FROM Posts WHERE ID = '$id'"; $conn->exec($sql); header("location: admin.php"); } catch(PDOException $e) { echo $sql …
Jump to PostMy 'later usage' is set because the ajax tempt to lose context, we need to save a reference to the object
$(this)
by assigning it to a variablebtn_dlt
so that when we wish to access this clicked button or its parent element, we can easily get it.
if(msg == …
Jump to Postok, so now have you checked the response from the ajax using developer tools from browser(F12)? If you wonder how to check, here is a print screen from my computer(I am using chrome).
F12->network, then click the button to trigger the ajax, my ajax request url is b.php, yours should …
Jump to PostIf that doesn't work either, sorry to tell you this but I can't seem to debug why the code not working properly.
Jump to PostMy idea? maybe json formatting? Try download and test using this code and compare with your code
https://dl.dropboxusercontent.com/u/95553471/b.php
All 44 Replies
lps
71
Posting Pro in Training
Niloofar24
15
Posting Whiz
Niloofar24
15
Posting Whiz
lps
71
Posting Pro in Training
lps
71
Posting Pro in Training
Niloofar24
15
Posting Whiz
Niloofar24
15
Posting Whiz
Niloofar24
15
Posting Whiz
Niloofar24
15
Posting Whiz
Eagle.Avik
0
Junior Poster in Training
Eagle.Avik
0
Junior Poster in Training
Niloofar24
15
Posting Whiz
Niloofar24
15
Posting Whiz
Niloofar24
15
Posting Whiz
Niloofar24
15
Posting Whiz
Niloofar24
15
Posting Whiz
lps
71
Posting Pro in Training
Niloofar24
15
Posting Whiz
lps
71
Posting Pro in Training
Niloofar24
15
Posting Whiz
lps
71
Posting Pro in Training
Niloofar24
15
Posting Whiz
lps
71
Posting Pro in Training
Niloofar24
15
Posting Whiz
lps
71
Posting Pro in Training
Niloofar24
15
Posting Whiz
lps
71
Posting Pro in Training
lps
71
Posting Pro in Training
Niloofar24
15
Posting Whiz
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.