Jump to content

passing variable from select dropdown list.


kevdoug

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]
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]
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 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.
[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.

Archived

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

×
×
  • Create New...

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.