error on POSTed form

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

    error on POSTed form

    I'm having a very hard time trying to add an edited listing to mySQL. I'm
    breaking this in to two halves, so that each error/problem can [hopefully]
    be pinpointed.

    The edit form queries mySQL and fills in a form with their existing
    information (identical form to the original "Add Me" form, but this time
    echo'ing the data currently in mySQL). This part works great. Once they
    have edited their information, Submit takes them to a page called save.php.
    Now the problems start. Below are my errors, followed by the section of the
    code to which they are referring. The errors are all fields where checkboxes
    were UNchecked -- the variables that were checked are not cited as errors.

    Warning: Undefined index: hair in /home/httpd/httpdocs/html/save.php on line
    33
    Warning: Undefined index: tv in /home/httpd/httpdocs/html/save.php on line
    36
    Warning: Undefined index: film in /home/httpd/httpdocs/html/save.php on line
    37
    Warning: Undefined index: bridal in /home/httpd/httpdocs/html/save.php on
    line 39

    My code, beginning at line 20, is:
    <?PHP
    error_reporting (E_ALL);
    $firstname = (ucwords(strtol ower(trim($_POS T['firstname']))));
    $lastname = (ucwords(strtol ower(trim($_POS T['lastname']))));
    $city= (ucwords(strtol ower(trim($_POS T['city']))));
    $state= (strtoupper($_P OST['state']));
    $country= (strtoupper($_P OST['country']));
    $availability= (addslashes($_P OST['availability']));
    $experience= (addslashes($_P OST['experience']));
    $email= (strtolower($_P OST['email']));
    $website= (strtolower($_P OST['website']));
    $newpasswd = ($_POST['website']);
    $makeup = ($_POST['makeup']);
    $hair = ($_POST['hair']);
    $wardrobe = ($_POST['wardrobe']);
    $print = ($_POST['print']);
    $tv = ($_POST['tv']);
    $film = ($_POST['film']);
    $video = ($_POST['video']);
    $bridal = ($_POST['bridal']);
    $artistID = ($_POST['artistID']);

    FWIW, I have tried the checkboxes both with and without the ( ) around the
    $_POST... Do I have to handle anything differently to account for UNchecked
    checkboxes, which presumably aren't passed?

    Thanx!
    Wm







  • Jamie Davison

    #2
    Re: error on POSTed form

    >Do I have to handle anything differently to account for UNchecked[color=blue]
    >checkboxes, which presumably aren't passed.[/color]


    These variables are passed but are passed as null or empty values.

    Try an function such like is_null($i) or empty($i)

    eg

    if ((is_null($i)) || (!empty($i))){
    .....
    }


    reference : http://us4.php.net/manual/en/function.empty.php

    -JD



    "Wm" <LAshooter@hotm ail.com> wrote in message
    news:3Yv%a.2441 345$cI2.329046@ news.easynews.c om...[color=blue]
    > I'm having a very hard time trying to add an edited listing to mySQL. I'm
    > breaking this in to two halves, so that each error/problem can [hopefully]
    > be pinpointed.
    >
    > The edit form queries mySQL and fills in a form with their existing
    > information (identical form to the original "Add Me" form, but this time
    > echo'ing the data currently in mySQL). This part works great. Once they
    > have edited their information, Submit takes them to a page called[/color]
    save.php.[color=blue]
    > Now the problems start. Below are my errors, followed by the section of[/color]
    the[color=blue]
    > code to which they are referring. The errors are all fields where[/color]
    checkboxes[color=blue]
    > were UNchecked -- the variables that were checked are not cited as errors.
    >
    > Warning: Undefined index: hair in /home/httpd/httpdocs/html/save.php on[/color]
    line[color=blue]
    > 33
    > Warning: Undefined index: tv in /home/httpd/httpdocs/html/save.php on line
    > 36
    > Warning: Undefined index: film in /home/httpd/httpdocs/html/save.php on[/color]
    line[color=blue]
    > 37
    > Warning: Undefined index: bridal in /home/httpd/httpdocs/html/save.php on
    > line 39
    >
    > My code, beginning at line 20, is:
    > <?PHP
    > error_reporting (E_ALL);
    > $firstname = (ucwords(strtol ower(trim($_POS T['firstname']))));
    > $lastname = (ucwords(strtol ower(trim($_POS T['lastname']))));
    > $city= (ucwords(strtol ower(trim($_POS T['city']))));
    > $state= (strtoupper($_P OST['state']));
    > $country= (strtoupper($_P OST['country']));
    > $availability= (addslashes($_P OST['availability']));
    > $experience= (addslashes($_P OST['experience']));
    > $email= (strtolower($_P OST['email']));
    > $website= (strtolower($_P OST['website']));
    > $newpasswd = ($_POST['website']);
    > $makeup = ($_POST['makeup']);
    > $hair = ($_POST['hair']);
    > $wardrobe = ($_POST['wardrobe']);
    > $print = ($_POST['print']);
    > $tv = ($_POST['tv']);
    > $film = ($_POST['film']);
    > $video = ($_POST['video']);
    > $bridal = ($_POST['bridal']);
    > $artistID = ($_POST['artistID']);
    >
    > FWIW, I have tried the checkboxes both with and without the ( ) around the
    > $_POST... Do I have to handle anything differently to account for[/color]
    UNchecked[color=blue]
    > checkboxes, which presumably aren't passed?
    >
    > Thanx!
    > Wm
    >
    >
    >
    >
    >
    >
    >[/color]


    Comment

    • Andy Hassall

      #3
      Re: error on POSTed form

      On Sat, 16 Aug 2003 22:44:36 GMT, "Jamie Davison" <jamie@bardavon .org> wrote:
      [color=blue][color=green]
      >>Do I have to handle anything differently to account for UNchecked
      >>checkboxes, which presumably aren't passed.[/color]
      >
      >These variables are passed but are passed as null or empty values.
      >
      >Try an function such like is_null($i) or empty($i)
      >
      >eg
      >
      >if ((is_null($i)) || (!empty($i))){
      > .....
      >}[/color]

      No, they're not passed at all. Only 'successful' controls (as defined in the
      HTML specs) are passed. A set variable or array element with a NULL or empty
      value is distinct from an unset variable.

      Use isset() to determine if the variable has been passed or not.

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd">
      <html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <title>form test</title>
      </head>
      <body>
      <form action="" method="get">
      <input type="checkbox" name="check1" value="T">
      <input type="submit">
      </form>
      <hr>
      <pre>
      <?php
      print_r($_GET);
      ?>
      </body>
      </pre>
      </html>

      Submit this form with and without the checkbox set; you'll see that check1 is
      NOT passed as a null or empty value if the checkbox is unchecked, it simply is
      not passed at all.

      Checked:

      Array
      (
      [check1] => T
      )

      Unchecked:

      Array
      (
      )

      --
      Andy Hassall (andy@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
      Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

      Comment

      Working...