Hi,
The following code was working fine locally but after uploading to server the function no longer redirects.
I have read a bunch of forums saying that the header may already be outputting but I am not sure if this is the case.
Does anyone see anything obvious why this is not working?
public function courseDelete($tableName,$id,$page){
if(isset($_GET['delete'])){
$query = "DELETE FROM $tableName where id = '$id'";
$result = mysql_query($query);
if(!$result) {
} else {
header("Location:".$page.".php?status=you have successfully deleted the item from the database");
}
}
}
It could be that the header() function isn’t being called.
If !$result you do and say nothing, so it could be that your query is failing. Throw an echo in there to do some debugging.
There are also some security problems with this code:
using GET to initiate an edit or delete makes CSRF attacks easier. Depending on your setup you could also have search engines following links that delete stuff.
are $tableName and $id escaped to avoid SQL Injection?
I know the query is working as the item is getting deleted from the database, $page is returning ‘faqs’ which I can get from the URL - Does it have to be an absolute path in the header?
I am not very confident at PHP yet so in terms of security I am sure that I am doing a few things wrong at this stage.
This delete item section is within the administration side that I have set up and the login section to the administration side is using mysql_real_escape_string. Should I be taking the security a lot further?