kevdoug Posted July 25, 2006 Share Posted July 25, 2006 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 https://forums.phpfreaks.com/topic/15573-passing-variable-from-select-dropdown-list/ Share on other sites More sharing options...
zq29 Posted July 25, 2006 Share Posted July 25, 2006 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 https://forums.phpfreaks.com/topic/15573-passing-variable-from-select-dropdown-list/#findComment-63326 Share on other sites More sharing options...
wildteen88 Posted July 25, 2006 Share Posted July 25, 2006 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 https://forums.phpfreaks.com/topic/15573-passing-variable-from-select-dropdown-list/#findComment-63328 Share on other sites More sharing options...
kevdoug Posted July 25, 2006 Author Share Posted July 25, 2006 [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 https://forums.phpfreaks.com/topic/15573-passing-variable-from-select-dropdown-list/#findComment-63330 Share on other sites More sharing options...
kevdoug Posted July 25, 2006 Author Share Posted July 25, 2006 [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 https://forums.phpfreaks.com/topic/15573-passing-variable-from-select-dropdown-list/#findComment-63331 Share on other sites More sharing options...
wildteen88 Posted July 25, 2006 Share Posted July 25, 2006 Make sure the form your select menu is contained in has a name of album in order that javascript to work. Link to comment https://forums.phpfreaks.com/topic/15573-passing-variable-from-select-dropdown-list/#findComment-63387 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.