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 Postthere is some problem with your script
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $dbusername, $dbpassword
specially how are you using
$servername
and$dbname
inside quote!! shouldn't it be:$conn = new PDO("mysql:host=".$servername.";dbname=".$dbname, $dbusername, $dbpassword
cause i thought variables don't work inside …
Jump to Postalso should not you use html form
<input type='submit' name='submit' value='Delete'" .$row['ID']. ">
how are you submitting it, are you using ajax and jquery??
as +lps mentioned, you should use ajax to call the script or use form.
here is a sollution:
you should probably use:
…
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 PostMy Request URL:http://localhost:4848/b.php is in General section under Headers tab. I think should be the things you mentioned.
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.