I am using an anchor tag to run the JS function confirm(), and if the user clicks okay it adds "deltopic=id", and use the $_GET method to get 'deltopic' to delete that specific item, but it seems to not be finding the $_GET['deltopic']
<script language="JavaScript" type="text>
function deltopic(title, tid) {
if(confirm("Are you sure you want to delete '" + title + "'")){
window.location.href = "?viewtopic.php&deltopic=" + tid;
}
}
</script>
<?php
if(isset($_GET['deltopic'])){
if($_GET['deltopic'] !=='1'){
$query = "DELETE FROM `bkg`.`bkg_topics` WHERE `bkg_topics`.`topic_id` = :topicid";
$query_params = array(':topicid' => $_GET['deltopic']);
try{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
header('Location: index.php?forums&action=deleted');
exit;
} catch(PDOException $e) {
$error[] = "An error has occured. Please try again later.";
}
}
echo "deltopic is set";
}
I added the last echo just to see if its checking if deltopic isset, or if it was an error in my SQL that I was just not seeing. However I do not see "deltopic is set".
I am not sure what I am doing wrong and/or what I am forgetting. I have code similar to this, that does work, and double checked it closely.
EDIT: I saw the error I was doing in my 'window.location.href' string, where I was adding .php to the end of ?viewtopic, making it ?viewtopic.php. Removing the .php fixed my issue as well.
window.location.href = "viewtopic.php?deltopic=" + tid;window.location.href = "viewtopic.php?deltopic=" +id;, ran into some other problems but figured it out ^.^ Thanks.