Why wont this access an array???

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

    Why wont this access an array???

    Can someone please tell me how to access elements from a multiple
    selection list? From what ive read on other posts, this is correct. I
    keep getting an "Undefined variable" error though...

    Form page*********** *************** *************** *************** ****
    <form action="/process.php" method="get" name="formOne" id="formOne">
    <select name="owner[]" size="6" multiple id="owner[]">
    <option value="one">one </option>
    <option value="two">two </option>
    <option value="three">t hree</option>
    </select>
    <input type="submit" name="Submit" value="Submit">
    </form>


    Process page*********** *************** *************** *************** **
    for($i=0; $i < count($owner); $i++) {
    echo $owner[$i];
    }

    Thanks! -Nick
  • Marcus

    #2
    Re: Why wont this access an array???

    Nick wrote:
    [color=blue]
    > Process page*********** *************** *************** *************** **
    > for($i=0; $i < count($owner); $i++) {
    > echo $owner[$i];
    > }
    >
    > Thanks! -Nick[/color]

    replace echo $owner[$i];

    with

    echo $_GET["owner"][$i];

    - Marcus


    Comment

    • Marius Mathiesen

      #3
      Re: Why wont this access an array???

      Nick wrote:[color=blue]
      > Can someone please tell me how to access elements from a multiple
      > selection list? From what ive read on other posts, this is correct. I
      > keep getting an "Undefined variable" error though...
      >
      > Form page*********** *************** *************** *************** ****
      > <form action="/process.php" method="get" name="formOne" id="formOne">
      > <select name="owner[]" size="6" multiple id="owner[]">
      > <option value="one">one </option>
      > <option value="two">two </option>
      > <option value="three">t hree</option>
      > </select>
      > <input type="submit" name="Submit" value="Submit">
      > </form>[/color]
      [color=blue]
      > Process page*********** *************** *************** *************** **
      > for($i=0; $i < count($owner); $i++) {
      > echo $owner[$i];
      > }[/color]

      Just a hunch... Have you defined the variable $owner? If not, you are
      probably depending on register_global s to being "on", which it may not
      be in your system. Try using the following:
      $owner = $_GET["owner"];
      before your for... loop.

      HTH
      --
      Marius

      Comment

      Working...