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]
Link to comment
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]
Link to comment
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.
Link to comment
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.
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.