I've been looking at this for some time now, all I'm doing is learning php with mysql, with no previous programming experience before these so please be kind. I need to delete an entire row from a table. The table is inside list.php
and there's a delete button that redirects to delete.php
. But all it does it redirects me to a blank page with an url something like "delete.php?id=4"
depending on row ID, which seems to be correct.
This is connect.php
:
<?php
$server = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "school";
$db_conn = mysqli_connect($server, $db_user, $db_pass, $db_name);
$connect_error = 'Sorry, we are experiencing connection problems';
mysql_connect('localhost', 'root', '') or die($connect_error);
mysql_select_db('school') or die($connect_error);
?>
And this is delete.php
:
<?php
if(isset($_GET['ID'])){
$courseID = $_GET['ID'];
$sql_delete = "DELETE FROM Courses WHERE ID = $courseID";
print ($sql_delete);
$result = mysqli_query($db_conn,$sql_delete);
if($result) {
echo "Congratulations. You have deleted this course succesfully.";
header('location:list.php');
} else {
echo "Error";
error_reporting(E_ALL ^ E_DEPRECATED);
}
}
?>
Notice "print ($sql_delete);
", which doesn't print anything either. All I can think of is there is something wrong with the way I am asking for the ID by using $_GET
, but can't get my head around it. When I run
"DELETE FROM Courses WHERE ID = 4;"
inside xampp's mysql module, it works. Uhm... oh well.
OK, let me add: This is actually my delete button inside list.php, which gives me an URL based on table row number, based on Course id.
<?php echo "<td><a href=\"delete.php?id=$row[ID]\">Delete</a>";?>
$_GET['ID']
must be$_GET['id']
– Paul Spiegel Dec 13 '15 at 11:37$courseID = mysqli_real_escape_string($_GET['id']);
– timgavin Dec 13 '15 at 11:57