+ Reply to Thread
Results 1 to 5 of 5

Thread: Verify Delete JS function

  1. #1
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    Verify Delete JS function

    I am using the following JS to verify whether they wish to delete or not. For some reason when i click the delete button and click ok it does not delete the entry, but if i click it a second time it does delete it. Anyone have any suggestions to how i can solve this issue?

    Code:
    function delete_record (form)
    {
     var coupon1 = form.coupon1.value;
     var where_to = confirm("Do you really want to delete " + coupon1 + "?");
     if (where_to == true)
     {
         var delete_var = form.delete_id.value;
        var delete_url = "delete.php?id=" + delete_var;
       window.location = delete_url;
     }
    }
    This is the form

    Code:
    <form class='delete_buttons' method='POST'>
    <input type='hidden' value='" . $recc['coupon'] . "' name='coupon1' />
    <input type='hidden' value='" . $recc['id'] . "' name='delete_id' />
    <input type='image' src='images/delete.gif' title='". $index_delete . $recc['coupon'] ."' onClick='delete_record(this.form)' />
    </form>
    This is the delete.php

    Code:
    $delete_id = $_GET['id'];
    $query = "DELETE FROM coupons where id=" . $delete_id . " LIMIT 1";
    mysql_query($query);
    echo '<meta http-equiv="refresh" content="0;url=index.php" />';

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Verify Delete JS function

    Quote Originally Posted by driveflexfuel View Post
    This is the form

    Code:
    <form class='delete_buttons' method='POST'>
    <input type='hidden' value='" . $recc['coupon'] . "' name='coupon1' />
    <input type='hidden' value='" . $recc['id'] . "' name='delete_id' />
    <input type='image' src='images/delete.gif' title='". $index_delete . $recc['coupon'] ."' onClick='delete_record(this.form)' />
    </form>
    The image input type is a submit button. If you use it, you must prevent the default submit handler. The more semantically sound approach is to use a <button> element with a style reset.

    Quote Originally Posted by driveflexfuel View Post
    Code:
    $delete_id = $_GET['id'];
    $query = "DELETE FROM coupons where id=" . $delete_id . " LIMIT 1";
    NO! NO! NO! You've opened yourself to SQL injection. Don't trust user input. Filter it with a filter function or escape it with either mysql_real_escape_string or mysql_escape_string

  3. #3
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Verify Delete JS function

    NO! NO! NO! You've opened yourself to SQL injection. Don't trust user input. Filter it with a filter function or escape it with either mysql_real_escape_string or mysql_escape_string
    Glad you showed me that. My site already has type error checking, length checking, format checking and so on. But the 'mysql_real_escape_string' function would add even more security.
    Thanks

  4. #4
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    Re: Verify Delete JS function

    Thanks for the info. I'm not worried about the security on this because it is under password protection and on an internal network server, but thanks for your concern.

  5. #5
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Verify Delete JS function

    You trust your users (and their computers) much more than I. Hopefully none of their computers will get infected by a worm that uses SQL injection. Remember Storm?

+ Reply to Thread

Similar Threads

  1. DW error message
    By bunglebrown in forum Scripts & 3rd Party Apps
    Replies: 3
    Last Post: 10-06-2008, 03:11 PM
  2. Replies: 2
    Last Post: 08-17-2008, 08:30 PM
  3. how to delete posts
    By dcoates in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 03-17-2008, 03:40 PM
  4. Easy XHTML form validation using PHP
    By Xemnas in forum Tutorials
    Replies: 0
    Last Post: 01-08-2008, 04:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers