I have a dynamic list that are links with url parameter that sends a record to a delete page. This page in turn receives the parameter and displays the record. below is the delete (submit button) The button re-directs to the correct page but no record is deleted. I have followed Dave Sawyer Mcfarland's tutorial but with no success. Can anyone help!
here you go!
<div id="content">
<h2>ADMIN/Delete</h2>
<p><?php echo $row_rsDeleteProperty['property_name']; ?></p>
<form action="delete.php" method="post">
<input name="Delete" type="submit" value="Delete Property" /><input name="Delete Bind" type="hidden" value="<?php echo $row_rsDeleteProperty['Property_id']; ?>" />
</form>
</div>
Assuming this is what you ment and not the entire page?
Hi Murray.. Here's the PHP code at top of page!
<?php require_once('../Connections/Properties_Agents.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($_POST['Delete'])) && ($_POST['Delete'] != "")) {
$deleteSQL = sprintf("DELETE FROM properties WHERE Property_id=%s",
GetSQLValueString($_POST['Delete'], "int"));
mysql_select_db($database_Properties_Agents, $Properties_Agents);
$Result1 = mysql_query($deleteSQL, $Properties_Agents) or die(mysql_error());
$deleteGoTo = "admin_edit.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));
}
$colname_rsDeleteProperty = "-1";
if (isset($_GET['Property_id'])) {
$colname_rsDeleteProperty = $_GET['Property_id'];
}
mysql_select_db($database_Properties_Agents, $Properties_Agents);
$query_rsDeleteProperty = sprintf("SELECT Property_id, property_name FROM properties WHERE Property_id = %s", GetSQLValueString($colname_rsDeleteProperty, "int"));
$rsDeleteProperty = mysql_query($query_rsDeleteProperty, $Properties_Agents) or die(mysql_error());
$row_rsDeleteProperty = mysql_fetch_assoc($rsDeleteProperty);
$totalRows_rsDeleteProperty = mysql_num_rows($rsDeleteProperty);
?>
In order to function properly, this page must know the ID value of the record it should delete. This code is responsible for getting that ID value, which should be a part of the Posted Data -
$deleteSQL = sprintf("DELETE FROM properties WHERE Property_id=%s",
GetSQLValueString($_POST['Delete'], "int"));
The ID value would be loaded into a field in your form on that page. Can we now see the HTML to verify its presence?
Really sorry Murray, but i don't understand the code you just posted or where I should put it. I am not a programmer and rely on Dreamweaver to produce most of it. Here's the complete page.
<?php require_once('../Connections/Properties_Agents.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($_POST['Delete'])) && ($_POST['Delete'] != "")) {
$deleteSQL = sprintf("DELETE FROM properties WHERE Property_id=%s",
GetSQLValueString($_POST['Delete'], "int"));
mysql_select_db($database_Properties_Agents, $Properties_Agents);
$Result1 = mysql_query($deleteSQL, $Properties_Agents) or die(mysql_error());
$deleteGoTo = "admin_edit.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));
}
$colname_rsDeleteProperty = "-1";
if (isset($_GET['Property_id'])) {
$colname_rsDeleteProperty = $_GET['Property_id'];
}
mysql_select_db($database_Properties_Agents, $Properties_Agents);
$query_rsDeleteProperty = sprintf("SELECT Property_id, property_name FROM properties WHERE Property_id = %s", GetSQLValueString($colname_rsDeleteProperty, "int"));
$rsDeleteProperty = mysql_query($query_rsDeleteProperty, $Properties_Agents) or die(mysql_error());
$row_rsDeleteProperty = mysql_fetch_assoc($rsDeleteProperty);
$totalRows_rsDeleteProperty = mysql_num_rows($rsDeleteProperty);
?>
<!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"><!-- InstanceBegin template="/Templates/masterC.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Description" content="" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>RTMF Master Template</title>
<!-- InstanceEndEditable -->
<link href="../css/reset.css" rel="stylesheet" type="text/css" />
<script src="../SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="../SpryAssets/SpryMenuBarVertical.css" rel="stylesheet" type="text/css" />
<link href="../css/global.css" rel="stylesheet" type="text/css" />
<link href="" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
</script>
<link href="jquery/jquery.twitter.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="jquery/jquery.twitter.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#twitter").getTwitter({
userName: "_rtmf_",
numTweets: 1,
loaderText: "Loading tweets...",
slideIn: true,
slideDuration: 750,
showHeading: true,
headingText: "Latest Tweet",
showProfileLink: false,
showTimestamp: true
});
});
</script>
<!-- InstanceBeginEditable name="spry" -->
<!-- InstanceEndEditable -->
<!-- InstanceParam name="id" type="text" value="home" -->
<!-- InstanceParam name="href" type="text" value="" -->
<!-- InstanceParam name="content" type="text" value="" -->
</head>
<body id="home">
<div id="outerWrapper"> <a name="introTop" id="home"></a>
<div id="wrapper">
<div id="banner">
<h1>The Right to Manage Federation</h1>
</div>
<div id="topNav">
<ul>
<li><a id="homeLink" href="../index.php">Home</a></li>
<li><a id="aboutUsLink" href="../about-rtmf.php">About Us</a></li>
<li><a id="newsLink" href="../rtmf-news.php">News</a></li>
<li><a id="contactLink" href="../ContactForm/contactus.php">Contact Us</a></li>
</ul>
</div>
<!-- InstanceBeginEditable name="bodyContent" -->
<div id="content">
<h2>ADMIN/Delete</h2>
<p><?php echo $row_rsDeleteProperty['property_name']; ?></p>
<form action="delete.php" method="post">
<input name="Delete" type="submit" value="Delete Property" /><input name="Delete Bind" type="hidden" value="" />
</form>
</div>
<!-- InstanceEndEditable -->
<div id="leftSide">
<ul id="MenuBar1" class="MenuBarVertical">
<li class="arhLink"><a href="#">About RTM</a></li>
<li class="arLink"><a id="privateLink" href="../rtm-for-private-residential/introduction.php">Private Residential</a></li>
<li class="arLink"><a id="retirementLink" href="../rtm-for-retirement-blocks/introduction.php">Retirement Blocks</a></li>
<li class="arhLink"><a href="#">About Leasehold</a></li>
<li class="alLink"><a id="understandingLink" href="../about-leasehold/understanding-leasehold.php">Understanding Leasehold</a></li>
<li class="alLink"><a id="issuesLink" href="../about-leasehold/common-issues.php">Common Issues</a></li>
<li><a id="testimonialsLink" href="../testimonials.php">Testimonials</a></li>
<li><a id="agentsLink" href="../agents.php?Agent_id=1">Managing Agents</a></li>
<li><a id="linksLink" href="../useful-links.php">Useful Links</a></li>
</ul>
<script type="text/javascript">
<!--
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
//-->
</script><!-- InstanceBeginEditable name="left content" --><!-- InstanceEndEditable -->
<a class="twitter" href="http://www.twitter.com/#!_rtmf_">Follow us on Twitter</a> </div>
<br class="clearfloat" />
</div>
</div>
<div id="footer">
<table width="950" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
<td><p>Web-pages relevent to<br />
private residential properties</p></td>
<td><p>Web-pages relevent to<br />
retirement blocks</p></td>
<td> </td>
</tr>
<tr>
<td><ul class="footerNav">
<li><a href="../index.php">home</a></li>
<li><a href="../about-rtmf.php">About us</a></li>
<li><a href="../rtmf-news.php">News</a></li>
<li><a href="../ContactForm/contactus.php">Contact Us</a></li>
</ul></td>
<td><ul class="footerNav">
<li><a href="../rtm-for-private-residential/introduction.php">RTM Introducti on</a></li>
<li><a href="../rtm-for-private-residential/how-it-works.php">How It Works</ a></li>
<li><a href="../rtm-for-private-residential/do-you-qualify.php">Do You Quali fy</a></li>
<li><a href="../rtm-for-private-residential/rtmf-fees.php">RTM Fees</a></li>
<li><a href="../rtm-for-private-residential/faq.php">FAQ's</a></li>
<li><a href="../rtm-for-private-residential/downloads.php">Downloads</a></li >
</ul></td>
<td><ul class="footerNav">
<li><a href="../rtm-for-retirement-blocks/introduction.php">Introduction</a> </li>
<li><a href="../rtm-for-retirement-blocks/how-it-works.php">How it Works</a></li>
<li><a href="../rtm-for-retirement-blocks/selection-process.php">Management Selection</a></li>
<li><a href="../rtm-for-retirement-blocks/procedure.php">Step by Step Proced ure</a></li>
<li><a href="../rtm-for-retirement-blocks/faq.php">FAQ's for Retirement</a>< /li>
<li><a href="../rtm-for-retirement-blocks/downloads.php">downloads</a></li>
</ul></td>
<td><ul class="footerNav">
<li><a href="../about-leasehold/understanding-leasehold.php">Understanding L easehold</a></li>
<li><a href="../about-leasehold/common-issues.php">Common Issues</a></li>
<li><a href="../useful-links.php">Useful Links</a></li>
<li><a href="../testimonials.php">Testimonials</a></li>
<li><a href="../agents.php">Managing Agents</a></li>
<li><a href="login.php">Admin</a></li>
</ul></td>
</tr>
</table>
<p id="dec">The Right To Manage Federation Ltd. Copyright © 2012, RTMF. All rights reserved. Calverley House, 55 Calverley Road, Tunbridge Wells, Kent, TN1 2TU.</p>
<br class="clearfloat" />
</div>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($rsDeleteProperty);
?>
The code I quoted is already ON your page - I was just pointing out that it was the part of your page that is responsible for determining which record to delete. As written, it requires a field to be in the form called "Delete" but you don't have that. You have this -
<input name="Delete" type="submit" value="Delete Property" /><input name="Delete Bind" type="hidden"
There are three problems here - 1) you can't have a space in a name attribute value, and 2) the field needs to be named ONLY "Delete", and finally 3) the field needs to be loaded with the property ID before the form is submitted.
Which tutorial are you following?
Ok! So I think I am able to correct point one and two. But As I stated before, I am not programmer, consequently I am not sure how I would correct point three. I am a novice when it comes to php driven pages and struggle understanding much of the code structure.
Where and how in the code would the field be loaded with the Property ID.
Incidentally, I am using an 'OReilly' Publication - Dreamweaver CS5 'the missing manual' by David Sawyer Mcfarland'
SJgooner wrote:
I am not programmer, consequently I am not sure how I would correct point three. I am a novice when it comes to php driven pages and struggle understanding much of the code structure.
If you're planning to deploy a PHP/MySQL site on the internet, you need to learn the basics of PHP and MySQL very soon. Otherwise, you are going to lay yourself open to a lot of grief. It's not difficult, but it does take time and effort to learn.
Lecture over, now to solve your problem...
The command that deletes the record is looking for a form field called "Delete" which contains the value of Property_id.
Murray is correct about not being allowed to have spaces in the name attribute. However, you've got two form elements that contain "Delete" in the name. To fix the page so that it works, you need to amend the form like this:
<p><?php echo $row_rsDeleteProperty['property_name']; ?></p>
<form action="delete.php" method="post">
<input name="Delprop" type="submit" value="Delete Property" /><input name="Delete" type="hidden" value="<?php echo $row_rsDeleteProperty['Property_id']; ?>" />
</form>
By the way, you shouldn't rely on Dreamweaver's server behaviors. Although basically sound, they use very old code that has been deprecated by PHP. I wouldn't count on server behaviors being around in years to come, although they can be a useful learning tool.
Just a quick follow-up to explain the meaning of the code I have added.
As I said, the command that's performing the delete operation is looking for a form field with the name "Delete" that contains the Property_id. The purpose of the hidden form field is to store the Property_id, and to send it in the POST array when the Delete Property button is clicked. The hidden field, therefore, needs to be called "Delete", and the code that I added stores the value of Property_id as its value. Because the hidden field needs to be called "Delete", I changed the name of the submit button to "Delprop".
David.
Firstly, I probably devalued myself too much as I am gradually getting to grips with php do have a basic understanding of how it works . As always it is never a good idea to use Dreamweaver for advanced tasks such as this, but you have start somewhere. It is sometimes difficult to find your way around the structure when you are still learning!
Incidentally, I do believe I ordered a book publised by yourself - 'PHP Solutions: Dynamic Web Design Made Easy'. I hopw this will help my development!
Many thanks for your's and Murray's help!
That's excellent news that you're taking steps to learn PHP. Sadly, many people who post in these forums take the attitude that Dreamweaver should do everything for them. Your positive attitude is a breath of fresh air.
Of course, I understand that everyone has to start somewhere. Even though I write books about PHP and Dremaweaver, I never forget that I was also a beginner once.
I hope you find the book useful. Make sure you check out the updates and corrections that I have posted at http://foundationphp.com/phpsolutions/errata_2e.php. It also tells you where to obtain all the example files. The location has changed since the book was printed.
North America
Europe, Middle East and Africa
Asia Pacific