Skip navigation
Currently Being Moderated

Delete record Server Behaviour not  deleting

Jun 29, 2012 6:35 AM

Tags: #php #dreamweaver

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!

 
Replies
  • Currently Being Moderated
    Jun 29, 2012 6:49 AM   in reply to Steve Joiner

    Let's see the code on the page that has the delete button, please.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 29, 2012 8:06 AM   in reply to Steve Joiner

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 29, 2012 9:02 AM   in reply to Steve Joiner

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 2, 2012 3:44 AM   in reply to Steve Joiner

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 2, 2012 3:51 AM   in reply to David_Powers

    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".

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 2, 2012 4:35 AM   in reply to Steve Joiner

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)