Removing a row which sits in the mysql database through dropdown list with php

I want to remove an item from dropdown list with php. but it does not remove an item.

This is the html part.

<form action="dashboard_delete_post.php" method="post">
<div class="post_lable_and_text"> 
<label class="title_style_lable" >Post Title </label>
 <select>								
		<?php show_Post_Content(); ?>								
</select> 
							
<button class="btn_post" type="submit" name="delete">Delete</button>
<?php delete_Post_Content(); ?>
</div>
</form>

This is the php code snippet in the hope of removing an item via dropdown list.

function delete_Post_Content() {

	global $db_link;	

	if (isset($_POST['delete'])) {
		
		$post_Id = $_POST['post_id'];
		$post_Title = $_POST['post_title'];
		
 		$removeSqlData = " DELETE FROM posts WHERE post_id = '$post_Id' ";

		$result = mysqli_query($db_link, $removeSqlData);

		if (!$result) {
		    echo "error!";  
		} 
	  }
	}

Is there any issue with this?

SO, I do not want to discuss the danger of this code, full of potential SQL INJECTIONS and with all the worst practices used in.

But the two parameters: post_id and post_title, are passed from the FORM?
Insert these two lines at the beginning of the page to see WARNING and ERROR and post them here.

error_reporting(E_ALL);
ini_set('display_errors', 1);

The errors could be everywhere, a wrong connection with DB, variables not defined, etc etc…

1 Like