Jump to content


Photo

passing variable from select dropdown list.


  • Please log in to reply
5 replies to this topic

#1 kevdoug

kevdoug
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 25 July 2006 - 11:53 AM

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.

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>




Here is how I am trying to show it on page 2

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


#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 25 July 2006 - 11:56 AM

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


#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 25 July 2006 - 11:58 AM

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:
<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>
Change page.php to the page you want the form to be submitted to.

#4 kevdoug

kevdoug
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 25 July 2006 - 12:02 PM

I don't think the select tag accepts a method attribute. You'll need to enclose it in a form...

<form name="myform" action="page2.php" method="post">
    <select name="myselect">
        <option value="1">ONE</option>
        <option value="2">TWO</option>
    </select>
</form>


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.

#5 kevdoug

kevdoug
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 25 July 2006 - 12:05 PM

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:

<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>
Change page.php to the page you want the form to be submitted to.


Thank you it was the (onchange="document.album.submit()") that I was missing.

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 25 July 2006 - 02:03 PM

Make sure the form your select menu is contained in has a name of album in order that javascript to work.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users