Multiple Checkboxes Help Needed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ralph Freshour

    Multiple Checkboxes Help Needed

    I'm using MySQL to display data on a web page - fitting about 10
    records of data per screen - I'm including a checkbox with each record
    so that I can check it and when the submit button is clicked the
    called .php script will delete those records that are checked.

    I'm creating the records from the table with the checkboxes ok (I
    think):

    <INPUT TYPE='checkbox'
    NAME='frm_chk_d elete[$php_delete_cou nter]'>Delete

    I use a php counter var to give each checkbox record item a unique
    NAME and this seems to work OK - producing
    frm_chk_delete[0]
    frm_chk_delete[1]
    etc.

    The problem I'm having is the POST called script - I don't seem to be
    detecting enabled checkboxes to delete them:

    $php_mem_name = Trim(StrToLower ($php_name));
    $php_SQL = "SELECT * FROM basics WHERE member_name =
    '".$php_mem_nam e."'";
    $php_resultID = mysql_query($ph p_SQL, $php_linkID);
    $php_delete_cou nter = 0;
    while ($php_row = mysql_fetch_obj ect($php_result ID))
    {
    if ($frm_chk_delet e[$php_delete_cou nter] == 'on')
    {
    $php_SQL = "DELETE FROM basics WHERE member_name =
    '".$php_mem_nam e."'";
    $php_resultID = mysql_query($ph p_SQL, $php_linkID);
    }
    $php_delete_cou nter++;
    }

    Can anyone see what I'm doing wrong or that I'm not understanding
    about how to do this task?

    Thanks...

  • Geoff Berrow

    #2
    Re: Multiple Checkboxes Help Needed

    I noticed that Message-ID: <34bimvo9sh69d5 im09viomebpmuff mpsgs@4ax.com>
    from Ralph Freshour contained the following:
    [color=blue]
    >Can anyone see what I'm doing wrong or that I'm not understanding
    >about how to do this task?[/color]

    You have to give the checkbox a value to return if checked. e.g
    <INPUT TYPE='checkbox'
    NAME="frm_chk_d elete[$php_delete_cou nter]" value="1">

    and detect like so...

    if ($frm_chk_delet e[$php_delete_cou nter] == 1)

    --
    Geoff Berrow
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • Ralph Freshour

      #3
      Re: Multiple Checkboxes Help Needed

      I tried that but it only detects the first checkbox - if I have 5
      records displayed and I check all 5 and then click on submit, only the
      first checkbox is detected as checked, the others do not get detected.

      I also tried:

      VALUE=<?php echo $php_delete_cou nter ?>

      in the checkbox so each would get a unique value but that didn't seem
      to matter either - maybe my syntax is wrong somewhere?:

      <INPUT TYPE="checkbox" NAME="frm_chk_d elete[$php_counter]"
      VALUE="1">Delet e

      Then in my called post php script:

      $php_SQL = "SELECT * FROM names WHERE member_name =
      '".$php_mem_nam e."'";
      $php_resultID = mysql_query($ph p_SQL, $php_linkID);
      $php_delete_cou nter = 0;
      while ($php_row = mysql_fetch_obj ect($php_result ID))
      {
      if ($frm_chk_delet e[$php_delete_cou nter] == 1)
      {

      }
      $php_delete_cou nter++;
      }


      On Thu, 18 Sep 2003 07:24:16 +0100, Geoff Berrow <$bl$@ckdog.co. uk>
      wrote:
      [color=blue]
      >I noticed that Message-ID: <34bimvo9sh69d5 im09viomebpmuff mpsgs@4ax.com>
      >from Ralph Freshour contained the following:
      >[color=green]
      >>Can anyone see what I'm doing wrong or that I'm not understanding
      >>about how to do this task?[/color]
      >
      >You have to give the checkbox a value to return if checked. e.g
      ><INPUT TYPE='checkbox'
      >NAME="frm_chk_ delete[$php_delete_cou nter]" value="1">
      >
      >and detect like so...
      >
      > if ($frm_chk_delet e[$php_delete_cou nter] == 1)[/color]

      Comment

      • Jon Kraft

        #4
        Re: Multiple Checkboxes Help Needed

        Ralph Freshour <ralph@primemai l.com> wrote:
        [color=blue]
        > I tried that but it only detects the first checkbox - if I have 5
        > records displayed and I check all 5 and then click on submit, only the
        > first checkbox is detected as checked, the others do not get detected.
        >
        > <INPUT TYPE="checkbox" NAME="frm_chk_d elete[$php_counter]"
        > VALUE="1">Delet e[/color]

        Hi Ralph,

        How do you build up the list of checkboxes? Are you sure $php_counter is
        incremented for each checkbox name?

        JOn

        Comment

        • Geoff Berrow

          #5
          Re: Multiple Checkboxes Help Needed

          I noticed that Message-ID: <eiejmv0f5q2t89 bct0bk9qm13jf9i 3bdgb@4ax.com>
          from Ralph Freshour contained the following:
          [color=blue]
          ><INPUT TYPE="checkbox" NAME="frm_chk_d elete[$php_counter]"[/color]
          ....[color=blue]
          > if ($frm_chk_delet e[$php_delete_cou nter] == 1)[/color]

          Could this be your problem?

          --
          Geoff Berrow
          It's only Usenet, no one dies.
          My opinions, not the committee's, mine.
          Simple RFDs http://www.ckdog.co.uk/rfdmaker/

          Comment

          • Chung Leong

            #6
            Re: Multiple Checkboxes Help Needed

            A simpler (as well as quicker) way to do this would be to use the id
            of the record as the value in the checkbox. Thus:

            $res_id = mysql_query("SE LECT * FROM basics");
            while($row = mysql_fetch_row ) {
            $id = $row[0];
            echo <<<CHECKBOX
            <input type="checkbox" name="frm_chk_d elete[]" value="$id"> ...
            CHECKBOX;
            }

            When the form is submit, the ids those records that are selected will
            be in frm_chk_delete. All you have to do to delete them is to run a
            DELETE using the IN keyword.

            $list_of_ids = implode(",", $frm_chk_delete );
            mysql_query("DE LETE FROM basics WHERE basics_id IN ($list_of_ids)" );

            $php_SQL = "SELECT * FROM basics WHERE member_name =[color=blue]
            > '".$php_mem_nam e."'";
            > $php_resultID = mysql_query($ph p_SQL, $php_linkID);
            > $php_delete_cou nter = 0;
            > while ($php_row = mysql_fetch_obj ect($php_result ID))
            >[/color]

            Ralph Freshour <ralph@primemai l.com> wrote in message news:<34bimvo9s h69d5im09viomeb pmuffmpsgs@4ax. com>...[color=blue]
            > I'm using MySQL to display data on a web page - fitting about 10
            > records of data per screen - I'm including a checkbox with each record
            > so that I can check it and when the submit button is clicked the
            > called .php script will delete those records that are checked.
            >
            > I'm creating the records from the table with the checkboxes ok (I
            > think):
            >
            > <INPUT TYPE='checkbox'
            > NAME='frm_chk_d elete[$php_delete_cou nter]'>Delete
            >
            > I use a php counter var to give each checkbox record item a unique
            > NAME and this seems to work OK - producing
            > frm_chk_delete[0]
            > frm_chk_delete[1]
            > etc.
            >
            > The problem I'm having is the POST called script - I don't seem to be
            > detecting enabled checkboxes to delete them:
            >
            > $php_mem_name = Trim(StrToLower ($php_name));
            > $php_SQL = "SELECT * FROM basics WHERE member_name =
            > '".$php_mem_nam e."'";
            > $php_resultID = mysql_query($ph p_SQL, $php_linkID);
            > $php_delete_cou nter = 0;
            > while ($php_row = mysql_fetch_obj ect($php_result ID))
            > {
            > if ($frm_chk_delet e[$php_delete_cou nter] == 'on')
            > {
            > $php_SQL = "DELETE FROM basics WHERE member_name =
            > '".$php_mem_nam e."'";
            > $php_resultID = mysql_query($ph p_SQL, $php_linkID);
            > }
            > $php_delete_cou nter++;
            > }
            >
            > Can anyone see what I'm doing wrong or that I'm not understanding
            > about how to do this task?
            >
            > Thanks...[/color]

            Comment

            Working...