Hello!
I’m having a problem doing the following:
Deleting a record from a table in a database by using a link with an URL-parameter.
I created this code using the standard code generating wizard that I can find in the Insert panel. I used the “Delete Record” behaviour.
This created the following code:
[php]<?php require_once('Connections/rickhurk_fotos.php'); ?>
<?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } if ((isset($_GET['id'])) && ($_GET['id'] != "")) { $deleteSQL = sprintf("DELETE FROM fotos WHERE id=%s", GetSQLValueString($_GET['id'], "int")); mysql_select_db($database_rickhurk_fotos, $rickhurk_fotos); $Result1 = mysql_query($deleteSQL, $rickhurk_fotos) or die(mysql_error()); $deleteGoTo = "index.php"; if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $deleteGoTo)); } ?>[/php]However, this does not work.
First of all, the redirect in this code doesn’t work, it just doesn’t redirect me.
I fixed this using javascript:
<script language="JavaScript">
setTimeout(function() {
window.location="index.php";
},100);
</script>
So now it does redirect me to where it should.
Unfortunately, not one record gets deleted from the database, which is the second problem. This last problem I cannot fix.
I would really appreciate some help with this.
Does this have to do with the redirect also not working? I mean, does the redirect not working mean that the php-code isn’t running well, or do these two problems have no connection at all?
Thanks in advance.