michaelkirby Posted March 31, 2010 Share Posted March 31, 2010 Hi all, I have a drop down reading from a table in the database. When I select the option from the drop down i would require this information to be passed over to another page. Can I use a link? If so is what I am doing correct? Please see the code I'm using below... drop down for category: <p>Select an existing industry:<br /> <select name="categories"> <?php $selectCategoryQuery = "SELECT * FROM categories ORDER BY categoryname"; $selectCategoryResult = mysql_query($selectCategoryQuery) or die(mysql_error()); while($row1Category=mysql_fetch_array($selectCategoryResult)) { ?> <?php echo '<option value="'.$row1Category['categoryid'].'">'.$row1Category['categoryname'].'</option>'; ?> <?php } ?> Then I was wondering how to pass the details to another page using a link?? <a href="addbrieftocategory.php?categoroyid=<?php echo $row['categoryid']?>" >[+] </a> Which then takes me to another page where I can insert this id into a database table. Can someone please advise me. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/197085-passing-values-from-drop-down-list-to-another-page/ Share on other sites More sharing options...
trq Posted March 31, 2010 Share Posted March 31, 2010 If you wrap your dropdowns within a form you can submit this form to another page (either by a submit button or an onChange() Javascript event). Quote Link to comment https://forums.phpfreaks.com/topic/197085-passing-values-from-drop-down-list-to-another-page/#findComment-1034601 Share on other sites More sharing options...
michaelkirby Posted March 31, 2010 Author Share Posted March 31, 2010 So when I wrap it in the form, the action pointing to the php page where I want the values to go I understand. But then to get the values? As I want to ultimately get the id and save it into a table. Quote Link to comment https://forums.phpfreaks.com/topic/197085-passing-values-from-drop-down-list-to-another-page/#findComment-1034606 Share on other sites More sharing options...
trq Posted March 31, 2010 Share Posted March 31, 2010 If you form uses the post method your data will be within the $_POST array, get will be within $_GET. Quote Link to comment https://forums.phpfreaks.com/topic/197085-passing-values-from-drop-down-list-to-another-page/#findComment-1034610 Share on other sites More sharing options...
michaelkirby Posted March 31, 2010 Author Share Posted March 31, 2010 Hi, Ok I understand that but maybe I have made a mistake in my code because I can't display the category id or write it to the db. Here is the code I'm using: Form: <form action="addbrieftocategory.php" method="get"> <p>Select a category:<br /> <select name="categories"> <?php $selectCategoryQuery = "SELECT * FROM categories ORDER BY categoryname"; $selectCategoryResult = mysql_query($selectCategoryQuery) or die(mysql_error()); while($row1Category=mysql_fetch_array($selectCategoryResult)) { ?> <?php echo '<option value="'.$row1Category['categoryid'].'">'.$row1Category['categoryname'].'</option>'; ?> <?php } ?> </select> <input name="Save" type="submit" value="Upload"> </form> Then the page the action goes to: <?php session_start(); require "connect.php"; $briefid = mysql_insert_id($connection); $categoryid = $_GET['categoryid']; echo $categoryid; $query = "insert into briefcat values ('".$briefid."','".$categoryid."') "; $result = @mysql_query($query, $connection)or die ("Unable to perform query<br>$query"); //header("Location: briefsassignedto.php"); //exit(); ?> Is this correct? Quote Link to comment https://forums.phpfreaks.com/topic/197085-passing-values-from-drop-down-list-to-another-page/#findComment-1034617 Share on other sites More sharing options...
trq Posted March 31, 2010 Share Posted March 31, 2010 The <select> is named catigories. $categoryid = $_GET['categories']; Quote Link to comment https://forums.phpfreaks.com/topic/197085-passing-values-from-drop-down-list-to-another-page/#findComment-1034620 Share on other sites More sharing options...
michaelkirby Posted March 31, 2010 Author Share Posted March 31, 2010 Thanks Thrope!!! Got it working now. Your help is much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/197085-passing-values-from-drop-down-list-to-another-page/#findComment-1034626 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.