SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: checkboxes

  1. #1
    SitePoint Enthusiast tommy168's Avatar
    Join Date
    Feb 2011
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question checkboxes

    Hey guys

    I am confused about using checkboxes to delete entries. Yes, just for delete.

    Codes for table:

    PHP Code:
    echo "<form method = \"post\" action=\"{$_SERVER['PHP_SELF']}\">
    <table>
    <tr>
    <td width=\"55\" class=\"formLabelsS2\"><input type=\"submit\" name=\"delete\" value=\"Delete\" id=\"delete\"></td>
    <td> Please note that entries could not be restored once they are deleted!</td>
    </tr>
    </table>
    </form>"
    ;


    echo 
    "<table class=\"sortable\" id=\"query_quick1\" width=\"100%\" >\r\n";
    echo 
    "<thead>";
    echo 
    "\t<tr><th></th><th></th><th>Up.dated Query</th><th>Link</th><th>Promoter</th><th> # </th><th>Up?</th>
    <th>Ana. Area</th><th> # </th><th>Up?</th>
    <th>C. Type</th><th> # </th><th>Up?</th><th>Other C. Type</th>
    <th> # </th><th>Up?</th><th>Gen. Back.</th><th> # </th><th>Up?</th>
    <th>Other Gen. Back.</th><th> # </th><th>Up?</th><th>Author</th><th> # </th><th>Up?</th>
    <th>Other</th><th> # </th><th>Up?</th><th>Date</th><th>Email</th>
    <th>F. Name</th><th>L. Name</th></tr>\r\n"
    ;
    echo 
    "</thead>";


    if(
    $result->num_rows){
    while (
    $row $result->fetch_array()){
    $RowCount ++;
    $row_color = ($RowCount 2) ? $color1 $color2;
    echo 
    "\t<tr class=\"$row_color\" >

    <form method = \"post\" action=\"
    {$_SERVER['PHP_SELF']}\">
    <td><input type =\"hidden\" name = \"id\" value=\"
    {$row['id']}\"></td>
    <td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"
    {$rows['id']} \"></td>

    <td>
    {$row['query']}</td><td>{$row['link']}</td>
    <td>
    {$row['pro']}</td><td>{$row['pro_count']}</td>
    <td>
    {$row['pro_update']}</td>
    <td>
    {$row['ana']}</td><td>{$row['ana_count']}</td><td>{$row['ana_update']}</td>
    <td>
    {$row['cell']}</td><td>{$row['cell_count']}</td><td>{$row['cell_update']}</td>
    <td>
    {$row['cellother']}</td><td>{$row['cellother_count']}</td><td>{$row['cellother_update']}</td>
    <td>
    {$row['gen']}</td><td>{$row['gen_count']}</td><td>{$row['gen_update']}</td>
    <td>
    {$row['genother']}</td><td>{$row['genother_count']}</td><td>{$row['genother_update']}</td>
    <td>
    {$row['author']}</td><td>{$row['author_count']}</td><td>{$row['author_update']}</td>
    <td>
    {$row['other']}</td><td>{$row['other_count']}</td><td>{$row['other_update']}</td>
    <td>
    {$row['date']}</td><td>{$row['Email']}</td>
    <td>
    {$row['First_Name']}</td><td>{$row['Last_Name']}</td>
    </form></tr>"
    ;
    }
    }
    echo 
    "</table>"

    php for deleting entries:

    PHP Code:
    } elseif(isset($_SESSION['user_id']) AND isset($_POST['delete'])){

    $connect=db_connect_2();

    foreach(
    $_POST['checkbox'] as $check)
    {
    $delete mysqli_query("DELETE FROM mailing_list WHERE id = '$check'");
    }
    $body "mailingList.php";

    Error pops up:

    Warning: Invalid argument supplied for foreach()


    Of course no entries are deleted due to this warning.

    Help would be greatly appreciated as always

    Thanks.

  2. #2
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    I cannot see where $_POST['delete'] is being formed, so that could be a reason.
    Ryan B | My Blog | Twitter

  3. #3
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you have Teamviewer installed PM me your connection details within 60 minutes of this post and I'll hop over to your desktop and debug this with you.
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    1) You create a new form for each entry? So each form has only one checkbox?
    2) Your forms have no submit button?
    3) You give the checkbox the value of $rows['id'], and that should be (I think) $row['id']

  5. #5
    SitePoint Enthusiast tommy168's Avatar
    Join Date
    Feb 2011
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you have Teamviewer installed PM me your connection details within 60 minutes of this post and I'll hop over to your desktop and debug this with you.
    Sorry tangoforce I don't have Teamviewer installed but it would be best if you could just help me fix my codes in your reply =)

    1) You create a new form for each entry? So each form has only one checkbox?
    2) Your forms have no submit button?
    3) You give the checkbox the value of $rows['id'], and that should be (I think) $row['id']
    1) Yes since i am using a while loop, so there is a checkbox near each entry respectively as usual

    2) There's one delete (submit) button above the table

    3) Yes it should be $row['id'], good point. But still the same warning pops up

    Thanks

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by tommy168 View Post
    1) Yes since i am using a while loop, so there is a checkbox near each entry respectively as usual
    A checkbox near each entry, ok. But all checkboxes should be part of one single form.
    2) There's one delete (submit) button above the table
    Above the table, and in another form. That's why you get the error. Clicking that button, you send that form and that form contains only the button. No other data (since all checkboxes have their own forms that will never be sent).
    Put the button and all checkboxes in one form and see what happens.

  7. #7
    SitePoint Enthusiast tommy168's Avatar
    Join Date
    Feb 2011
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    A checkbox near each entry, ok. But all checkboxes should be part of one single form.

    Put the button and all checkboxes in one form and see what happens.
    So what you are saying is to put that delete button inside the while loop as well?

    And I am confused about the putting all the checkboxes into one single form... So you are saying I take out the
    PHP Code:
    <td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"{$rows['id']} \"></td> 
    OUT of the while loop?

    I just want to select multiple entries by clicking the corresponding checkboxes then click a single delete button to do the job

    Sorry I am kind of lost here, 'cause I am new to checkboxes...

    hope you can clarify it a bit more

  8. #8
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tommy168 View Post
    Sorry I am kind of lost here, 'cause I am new to checkboxes...
    Thats why I offered assistance. TV is a free download if you'd spent 20 seconds to google it

    Nevermind, you made it clear you'd prefer to spend hours waiting for replies etc so I'll leave you to it. FYI, most people I've offered that kind of help to have jumped at it.
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.

  9. #9
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by tommy168 View Post
    So what you are saying is to put that delete button inside the while loop as well?
    You could do that, it would give you a delete button for each entry.
    But it's not what I had in mind.
    And I am confused about the putting all the checkboxes into one single form... So you are saying I take out the
    PHP Code:
    <td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"{$rows['id']} \"></td> 
    OUT of the while loop?
    No. That line must be inside the loop. The <form> and </form> should not be.

    I just want to select multiple entries by clicking the corresponding checkboxes then click a single delete button to do the job

    Sorry I am kind of lost here, 'cause I am new to checkboxes...

    hope you can clarify it a bit more
    No worries I'm trying to explain it to you, instead of just giving you the solution, so you can understand how it works.

    So putting all in one form it would become:
    PHP Code:
    echo "<form method = \"post\" action=\"{$_SERVER['PHP_SELF']}\">
    <table>
    <tr>
    <td width=\"55\" class=\"formLabelsS2\"><input type=\"submit\" name=\"delete\" value=\"Delete\" id=\"delete\"></td>
    <td> Please note that entries could not be restored once they are deleted!</td>
    </tr>
    </table>

    echo "
    <table class=\"sortable\" id=\"query_quick1\" width=\"100%\" >\r\n";
    echo 
    "<thead>";
    echo 
    "\t<tr><th></th><th></th><th>Up.dated Query</th><th>Link</th><th>Promoter</th><th> # </th><th>Up?</th>
    <th>Ana. Area</th><th> # </th><th>Up?</th>
    <th>C. Type</th><th> # </th><th>Up?</th><th>Other C. Type</th>
    <th> # </th><th>Up?</th><th>Gen. Back.</th><th> # </th><th>Up?</th>
    <th>Other Gen. Back.</th><th> # </th><th>Up?</th><th>Author</th><th> # </th><th>Up?</th>
    <th>Other</th><th> # </th><th>Up?</th><th>Date</th><th>Email</th>
    <th>F. Name</th><th>L. Name</th></tr>\r\n"
    ;
    echo 
    "</thead>";


    if(
    $result->num_rows){
      while (
    $row $result->fetch_array()){
        
    $RowCount ++;
        
    $row_color = ($RowCount 2) ? $color1 $color2;
        echo 
    "\t<tr class=\"$row_color\" >

        <td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"
    {$rows['id']} \"></td>

        <td>
    {$row['query']}</td><td>{$row['link']}</td>
        <td>
    {$row['pro']}</td><td>{$row['pro_count']}</td>
        <td>
    {$row['pro_update']}</td>
        <td>
    {$row['ana']}</td><td>{$row['ana_count']}</td><td>{$row['ana_update']}</td>
        <td>
    {$row['cell']}</td><td>{$row['cell_count']}</td><td>{$row['cell_update']}</td>
        <td>
    {$row['cellother']}</td><td>{$row['cellother_count']}</td><td>{$row['cellother_update']}</td>
        <td>
    {$row['gen']}</td><td>{$row['gen_count']}</td><td>{$row['gen_update']}</td>
        <td>
    {$row['genother']}</td><td>{$row['genother_count']}</td><td>{$row['genother_update']}</td>
        <td>
    {$row['author']}</td><td>{$row['author_count']}</td><td>{$row['author_update']}</td>
        <td>
    {$row['other']}</td><td>{$row['other_count']}</td><td>{$row['other_update']}</td>
        <td>
    {$row['date']}</td><td>{$row['Email']}</td>
        <td>
    {$row['First_Name']}</td><td>{$row['Last_Name']}</td>
    </tr>"
    ;
    }
    }
    echo 
    "</table>";
    echo 
    "</form>"
    As you can see, I deleted the two </form>'s you had, and added a new one at the end. I also deleted the hidden field with the id. It's useless, because you get that value from $_POST['checkbox'].

  10. #10
    SitePoint Enthusiast tommy168's Avatar
    Join Date
    Feb 2011
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    No worries I'm trying to explain it to you, instead of just giving you the solution, so you can understand how it works.
    THANKS guido2004

    you are called mentor for a reason


Bookmarks

Posting Permissions

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