PHP Select box value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dan Puskar
    New Member
    • Aug 2006
    • 1

    PHP Select box value

    Hi.

    I'm new to this forum & to PHP. Just have a little problem. I want to pass the value of a select box to a php script on another page.

    Here's the code:

    [PHP] $output .= "<select name = \"field_select\ ">";

    $result = mysql_query("SH OW COLUMNS FROM list");
    if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
    }
    if (mysql_num_rows ($result) > 0) {
    while ($row = mysql_fetch_ass oc($result)) {
    $output .= "<option value = \"$row[Field]\">$row[Field]</option>";
    echo($row[field]);
    #print_r($row);
    echo("<BR>");
    }
    }
    $output .="</select>";
    [/PHP]

    and what I want on the output is the item actually SELECTED in the select box. What I'm actually getting is this:

    FIELD NAME: Array=>Field

    from the code:

    [PHP]
    ############### ### SELECT BOX ASSIGNED TO VARIABLE $POTATO2
    $potato2 = $_POST['field_select'];
    echo("<B>FIELD NAME: </b>" . $potato2 ."<BR>");
    [/PHP]
    Can anyone help?
    Last edited by Niheel; Aug 11 '06, 02:16 AM.
  • Niheel
    Recognized Expert Moderator Top Contributor
    • Jul 2005
    • 2432

    #2
    Works for me.

    Anyone else experiencing the same problem as Dan is?
    niheel @ bytes

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      Can't see any really obvious errors (I'm not in a position to run it)

      However in

      $output .= "<option value = \"$row[Field]\">$row[Field]</option>";

      $row[Field]

      should probably be

      $row['Field']

      Not that I think this will cure the problem.

      Comment

      Working...