I have built a number of input forms with PHP admin pages for displaying data and delete pages for the server side script that deletes the entries. These delete links work properly on all of the sites except my own! When I click the delete link I get a blank page with the URL:
http://turtlerockstudiomarketing.com/TRSMdelete.php?id=15
Check out these pages if you think you can figure it out. They are currently unsecured. It has to be something silly, right?
ED-H wrote:
When I click the delete link I get a blank page
When you get a blank PHP page, it means there's an error, but that the display of errors has been turned off. There's a more detailed explanation in Why is my PHP page blank? in the Dreamweaver FAQ.
Here's the code:
<?php require_once('Connections/trs.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 contactform WHERE ID=%s",
GetSQLValueString($_GET['ID'], "int"));
mysql_select_db($database_trs, $trs);
$Result1 = mysql_query($deleteSQL, $trs) or die(mysql_error());
$deleteGoTo = "TRSMadmin.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TRSM delete</title>
</head>
<body>
</body>
</html>
ED-H wrote:
Here's the code:
There's nothing immediately obvious in the code. Did you use the technique described in the FAQ article to turn on the display of errors temporarily?
It's possible that Connections/trs.php is not accessible, or that there is something in that file that's causing headers to be output, thereby preventing the page from redirecting to TRSMadmin.php.
Adding the error display script results in this:
Parse error: syntax error, unexpected ':' in /home/turtlero/public_html/TRSM/TRSMdelete.php on line 1
I believe you stated earlier that this is unreliable for syntax errors.
If my database connection, Connections/trs.php, were not accessible, how could I be getting input on my admin page?
I have this exact same page set up on two other websites, character for character except for the connection name, and it works on both. Puzzling.
Thanks a lot for your suggestions.
ED-H wrote:
Adding the error display script results in this:
Parse error: syntax error, unexpected ':' in /home/turtlero/public_html/TRSM/TRSMdelete.php on line 1
Line 1 now contains the script that I asked you to put in to turn on the display of errors. Unfortunately, there was an error in that script. I used a colon instead of a semicolon. Sorry about that. I have now corrected the code in the Dreamweaver FAQ. Correct your version, and try it again.
If my database connection, Connections/trs.php, were not accessible, how could I be getting input on my admin page?
The path could be wrong. The whole point of displaying error messages is to try to find out where the error is being triggered. Until then, it's purely guesswork.
I corrected the line 1 script. Now there is no error message at all, whether I use the delete link from the admin page or go directly to the URL. The delete page (http://turtlerockstudiomarketing.com/TRSMdelete.php) is blank, and still fails to delete from the admin page.
If you right-click that page, and view the source code, you'll see that it contains the HTML code for the page. That means it's loading correctly. Looking back over your previous posts, it's now obvious why it's not working. PHP is a case-sensitive language. The example URL you gave uses id in lowercase, but the code in your Delete Record server behavior is looking for ID in uppercase.
Change the delete link to use uppercase, or change the Delete Record server behavior to use lowercase, and it should work.
ED-H wrote:
Remember back at the beginning of this mess when I said it had to be something silly?!
Case-sensititivity is very important in PHP, but it's certainly easy to miss.
Thanks, David. I just bought one of your books. You've been a great help in my php adventure.
Thanks for buying. Hope you find the book helpful.
North America
Europe, Middle East and Africa
Asia Pacific