Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Deleting Multiple Rows using Checkboxes

    Hi all,

    I am having a lot of problems getting this working. The follwoing is the code that i am using:

    printf("<tr><td><input type = checkbox name = \"delete[]\" value = \"<?=$myarray[$id]?>\"> </td></tr>, $myrow['name']);

    <form method = "post" action="delete.php">
    <input type="submit" name="delete" value = "delete">

    Delete.php:

    if(!$id]){
    echo "<b>Please make your selection.</b>";
    }//end if
    else {
    $sql = "DELETE FROM register WHERE id = '$myarray[$id]'";
    $result = mysql_query($sql);
    echo "<b>Information deleted.";
    }//end else

    Any help would greatly appreciated

    Thank You
    Gismo

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try changing
    $sql = "DELETE FROM register WHERE id = '$myarray[$id]'";
    to
    $sql = "DELETE FROM register WHERE id = '$_POST['myarray']";
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    New Coder
    Join Date
    Apr 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Thanks for your reply but it doesnt seem to work, its bringing up the following error:

    Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'

    Any suggestions?
    Thank you
    Gismo

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Missed a quote. Try

    $sql = "DELETE FROM register WHERE id = '$_POST['delete']'";
    Last edited by raf; 04-26-2004 at 08:51 PM.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #5
    New Coder
    Join Date
    Apr 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks again, but it is bringing up the same error:

    Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'

    Your help is very appreciated

    Thanks
    Gismo

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm. The query isn't correct anyway since you'll have a commadelimited list in $_POST['delete'] and i missed the '."' behind the postvariable.
    Normally, the id will have a numerical column-type, so no quotes are needed. Your query is then
    PHP Code:
    $sql "DELETE FROM register WHERE id In (" .$_POST['delete'] .")"
    If id is not a numerical column, then you either need to change the columntype in your db or set up some extra formprocessing where you loop through the array to buils a variable with the elements in, so that theu are enclosed in quotes.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •