W3C home > Mailing lists > Public > www-html@w3.org > December 2003

Re: Php Checkboxes

From: David Luo <webmaster@brezosoft.com>
Date: Fri, 19 Dec 2003 23:18:55 +0800
Message-ID: <001301c3c643$6fd822d0$33a8f2da@davidloo>
To: "AmirBehzad Eslami" <behzad@delphiarea.com>, <www-html@w3.org>
Hi AmirBehzad,

This is the answer I am looking for. 

Thank you very much.

Best Regards,

  ----- Original Message ----- 
  From: AmirBehzad Eslami 
  To: David Luo ; www-html@w3.org 
  Sent: Friday, December 19, 2003 10:52 PM
  Subject: Re: Php Checkboxes

  Dear David,

  Yes, here comes that simple answer:

  when the user did not select any item, there won't be any variable named "$prob".
  There should be at least one selection; otherwise PHP won't define the array named "$prob".

  The solution is to check whether this variable is defined or not?
  Here comes a sample PHP code:

      if (isset($prob)) {
          echo "Selected Items:<br />";

          foreach ($prob as $value) {
              echo "{$value}<br />";
      else {
          echo "User did not select any item.";

  Warm regards,
  AmirBehzad Eslami

  ----- Original Message ----- 
    From: David Luo 
    To: www-html@w3.org 
    Sent: Friday, December 19, 2003 10:13 AM
    Subject: Php Checkboxes

    There quite a few checkboxes on my pages 


    If i "check" any of them, it's able to update the tables successfully and add it to the database. I use array names for the checkboxes i.e. 

    <input type="checkbox" name="prob[]" value="hello"> Hello</input>

    However if i dont' select anything, upon hitting Submit, I would expect the array to be null or empty. However any reference i make to prob returns a message saying 

    Undefined variable: prob in /path on line 10

    The checks i have tried so far are 

    if (strcmp($prob[0],"") != 0)

    if($prob != null) 

    How does php deal with no checkbox selection ? There might be a very simple answer to it. 




Received on Friday, 19 December 2003 10:18:43 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:06:06 UTC