I was wondering how to make my code less cluttered and more re-usable. I have seperate delete.php files for deleting specific data from pages. For example I have Genre,Platform and Customers.
Genre Delete
//get value of ?id= from the url $DeleteID = $_GET['id']; echo $DeleteID; require("connect.php"); //Linking $link = connectToDB(); //SQL Query $sql = "DELETE FROM Genre WHERE GenreID = ".$DeleteID; //Execute $result = $link->query($sql); //Check if ($link->affected_rows == 1) { header( "Location: genre.php" ); } else { echo "Didn't Work"; } Platform Delete
<?php session_start(); //get value of ?id= from the url $DeleteID = $_GET['id']; echo $DeleteID; require("connect.php"); //Linking $link = connectToDB(); //SQL Query $sql = "DELETE FROM Platform WHERE PlatformID = ".$DeleteID; //Execute $result = $link->query($sql); //Check if ($link->affected_rows == 1) { header( "Location: platform.php" ); } else { echo "Didn't Work"; } I wanted to know if it was possible for these to be made into 1 delete file that I can alter, or statement. The user is redirected to these pages through a button in a table, and it redirects to the delete page with the PK ID of the record.