Jump to content

Archived

This topic is now archived and is closed to further replies.

kevdoug

passing variable from select dropdown list.

Recommended Posts

Hi I am having trouble passing a variable form a dropdown list retrieved from a database table and trying to pass it to another page but it won't pass it for some reason.

[color=blue]Here is the select from page 1

<select method="post" name = "album_name">
<?php
      $usrname = $_COOKIE[user_cookie];
     
      $conn = OCILogon("kevin", "kevin", "") or die ("connection failed");
     
      $stmt = OCIParse($conn, "select * from album where user_name = '$usrname' ");
     
      OCIExecute($stmt);
      echo "Executed";
   
      while (OCIFetch($stmt))
      {
      $record =OCIResult($stmt, 'ALBUM_NAME');
      echo " <option value = '$record'> $record</option>";
     
      }
       
OCIFreeStatement($stmt);
OCILogoff($conn);
?>
</select>[/color]


[color=red]
Here is how I am trying to show it on page 2

$album_name = $_POST['album_name'];
echo $album_name; [/color]

Share this post


Link to post
Share on other sites
I don't think the select tag accepts a method attribute. You'll need to enclose it in a form...
[code]<form name="myform" action="page2.php" method="post">
    <select name="myselect">
        <option value="1">ONE</option>
        <option value="2">TWO</option>
    </select>
</form>[/code]

Share this post


Link to post
Share on other sites
You'll need to create a form first, which will state where the data will be sent to and the method (GET/POST) then use javascript to submit the form, using the onchange attribute for the drop down menu. Like so:
[code]<form action="page.php" name="album" method="post">
  <select name="album_name" onchange="document.album.submit()">
<?php
      $usrname = $_COOKIE[user_cookie];

      $conn = OCILogon("kevin", "kevin", "") or die ("connection failed");

      $stmt = OCIParse($conn, "select * from album where user_name = '$usrname' ");

      OCIExecute($stmt);
      echo "Executed";

      while (OCIFetch($stmt))
      {
      $record =OCIResult($stmt, 'ALBUM_NAME');
      echo " <option value = '$record'> $record</option>";

      }

  OCIFreeStatement($stmt);
  OCILogoff($conn);
  ?>
  </select>
</form>[/code]
Change page.php to the page you want the form to be submitted to.

Share this post


Link to post
Share on other sites
[quote author=SemiApocalyptic link=topic=101782.msg403105#msg403105 date=1153828566]
I don't think the select tag accepts a method attribute. You'll need to enclose it in a form...
[code]<form name="myform" action="page2.php" method="post">
    <select name="myselect">
        <option value="1">ONE</option>
        <option value="2">TWO</option>
    </select>
</form>[/code]
[/quote]

Sorry I should have stated that I do have it cotained in a form as I am passing other variables of which all work, but these are simple inputs held within a table.

Share this post


Link to post
Share on other sites
[quote author=wildteen88 link=topic=101782.msg403107#msg403107 date=1153828717]
You'll need to create a form first, which will state where the data will be sent to and the method (GET/POST) then use javascript to submit the form, using the onchange attribute for the drop down menu. Like so:
[code]<form action="page.php" name="album" method="post">
  <select name="album_name" onchange="document.album.submit()">
<?php
      $usrname = $_COOKIE[user_cookie];

      $conn = OCILogon("kevin", "kevin", "") or die ("connection failed");

      $stmt = OCIParse($conn, "select * from album where user_name = '$usrname' ");

      OCIExecute($stmt);
      echo "Executed";

      while (OCIFetch($stmt))
      {
      $record =OCIResult($stmt, 'ALBUM_NAME');
      echo " <option value = '$record'> $record</option>";

      }

  OCIFreeStatement($stmt);
  OCILogoff($conn);
  ?>
  </select>
</form>[/code]
Change page.php to the page you want the form to be submitted to.
[/quote]

Thank you it was the [color=blue](onchange="document.album.submit()")[/color] that I was missing.

Share this post


Link to post
Share on other sites
Make sure the form your select menu is contained in has a name of album in order that javascript to work.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.