php msqli deleting row

Could any one please explain or show an example of how i can delete a row from my msql table with a delete this link…

This would go somewhere in your view page or edit page (or a particular row if it is for something else):
[php]Delete Page[/php]

I named this delete_page.php:

[php] // confirm that the ‘id’ variable has been set
if (isset($_GET[‘id’]) && is_numeric($_GET[‘id’]))
{

		  $db = new mysqli("localhost", "your_username", "your_password", "bhr_db");
		  /* check connection */
		  if (mysqli_connect_errno()) {
			  printf("Connect failed: %s\n", mysqli_connect_error());
			  exit();
		  }

            // get the 'id' variable from the URL
            $id = $_GET['id'];

		 if ($delete_stmt = $db->prepare('DELETE FROM pages WHERE id=? LIMIT 1'))
		 {
		
			$delete_stmt->bind_param('s', $id);		 
			$delete_stmt->execute();	 
			$delete_stmt->close();
		 
		 }
		 else
		 {
			 echo "ERROR: could not prepare SQL statement.";
	 
		 }
		 mysqli_close($db);
 
 		 header("Location: admin.php");
    }
    else
    // if the 'id' variable isn't set, redirect the user
    {
            header("Location: admin.php");
    }[/php]

shouldn’t WHERE id=? be WHERE id=$id ?

Sponsor our Newsletter | Privacy Policy | Terms of Service