php - Delete not deleting the selected post but its deleting the recently(newels) added post -
my update.php
file:
<?php ob_start(); session_start(); //declare basic variables $servername = "localhost"; $username = "bilal"; $password = "super"; $dbname = "coursework"; //create connection $link = mysqli_connect($servername, $username, $password, $dbname); //check connection if($link->connect_error){ die ("connection failed: " . $link->connect_error); } //security purpose, handiling escape string // $crested_by = $_post ['created_by']; $title = $_post['title']; $catagory = $_post['catagory']; $contact = $_post['contact']; $comment = $_post ['description']; $ses = $_session['email']; $date = date('y-m-d'); $availability = $_post ['availability']; $price = $_post ['price']; $id = $_post['wow']; // $created_by_id = $_session['created_by_id']; // $username = $_session['firstname']; if (isset($_post['del'])){ $deletequery=mysqli_query($link,"delete new_post id='$id'"); header ("location: added_posts.php"); } else if(isset($_post['update'])){ $sql = "update new_post set title='$title', contact='$contact', availability='$availability', price='$price', comment='$comment' id='$id'"; if (mysqli_query($link, $sql)){ echo "awesoke"; header("location:added_posts.php"); }else{ echo "error: sign unsuccessfull"; } } $link->close(); ?>
this update.php
file showing id
inside textbox
, doing id = text field value
. deleting added item deletes if have 3 posts id ( 4, 5, 6) id delete 6 first 5 4. displaying data in bootstrap cards. every delete button under post delete recent 1 added.
so you're trying delete recent record in database?
your problem sql statement you have
"delete new_post id='$id'"
this deleting record in new_post
id equal id posted form.
you must consider latest entry in table have largest id.
so use this:
delete new_post order id desc limit 1
attempt 2:
you want delete specific row based on id?
i suggest use prepared statements security
firstly try this:
$stmt = $link->prepare("delete new_post id= ?"); $stmt->bind_param('i', $_post['wow']); // can use $id $stmt->execute(); $stmt->close();
Comments
Post a Comment