ashrobbins87 Posted March 18, 2009 Share Posted March 18, 2009 Hi I'm having real trouble with this, and it should be such a basic thing. I have a drop down list on one page which reads values from my DB and lets the user choose one, this works fine. However I can't work out how to pass the option they have chosen to the next page, so that the values corresponding to their choice can be put into fields. Here is the code from the sending page, this is where I think the problem is, because when I try to echo $_POST["users"]; (the name of the <select>) on the next page, all it says it "Array". <form method="POST" action="../user.php" > <select name="users[]"> <?php $mysqli = mysqli_connect("localhost","root","pass","opp_group"); //Get list of users in drop down $getUsers_sql ="SELECT id, firstname, surname FROM cms_users ORDER BY firstname"; $getUsers_res = mysqli_query($mysqli, $getUsers_sql)or die(mysqli_error()); while ($row = mysqli_fetch_assoc($getUsers_res)) { echo '<option value="' . $row['id'] . '">' . $row['firstname'] . ' ' . $row['surname'] . '</option>'; $f = $row['firstname']; $s = $row['surname']; } echo "</select> <a href=\"javascript:eventWindow('../user.php?f=".$f."&s=".$s."');\"> <input type=\"submit\" name=\"viewuser\" value=\"View\" /> </a>"; ?> </form> Link to comment https://forums.phpfreaks.com/topic/149951-reading-from-previous-page-drop-down-list/ Share on other sites More sharing options...
Ayon Posted March 18, 2009 Share Posted March 18, 2009 would be nice to see how you're handling the form in the user.php Link to comment https://forums.phpfreaks.com/topic/149951-reading-from-previous-page-drop-down-list/#findComment-787537 Share on other sites More sharing options...
ashrobbins87 Posted March 18, 2009 Author Share Posted March 18, 2009 Well at the moment I'm just trying to echo the value to makes sure it receives it correctly. But i eventually want it in a table. This is user.php at the moment... <?php echo "".$_POST["users"].""; echo " <table> <tr> <td><input type=\"submit\" name=\"update\" value=\"Update User\"></td> <td><a href=\"javascript:eventWindow('cms/deletevalidation.php');\"><input type=\"submit\" name=\"delete\" value=\"Delete\"></a></td> </tr> </table> <br/><br/> <table> <tr><td>First Name: </td><td><input type=\"text\" name=\"firstname\" size=\"20\">".$f."</input></tr> <tr><td>Surname: </td><td><input type=\"text\" name=\"surname\" size=\"20\" >".$s."</input></tr> <tr><td>Username: </td><td><input type=\"text\" name=\"username\" size=\"20\"></tr> <tr><td>Password: </td><td><input type=\"text\" name=\"password\" size=\"20\"></tr> </table>"; ?> The snippet of javascript in there is to do with a separate function and not related to this. Link to comment https://forums.phpfreaks.com/topic/149951-reading-from-previous-page-drop-down-list/#findComment-787541 Share on other sites More sharing options...
Stephen68 Posted March 18, 2009 Share Posted March 18, 2009 That's because it's an array I think using the [] in the name makes it an array, do you want them to pick multiple names? your code.. <select name="users[]"> If you are just picking one name then maybe just put it like this <select name="users"> Or you could just echo out the one result from the array like this <?php $nameArray = $_POST['users']; echo $nameArray[0]; ?> hope this helps in some way Stephen Link to comment https://forums.phpfreaks.com/topic/149951-reading-from-previous-page-drop-down-list/#findComment-787592 Share on other sites More sharing options...
ashrobbins87 Posted March 18, 2009 Author Share Posted March 18, 2009 Yeah, I know its because its an array, the book I'm using said to use the [] because I could be sending any of the options, and apparently it lets the user choose the option they want?? Am I missing something here? Sure the code from the initial page to post something is <form method="POST" action="../user.php" > <select name= "users" > and to receive it on the next page its just echo $_POST["users"]; Link to comment https://forums.phpfreaks.com/topic/149951-reading-from-previous-page-drop-down-list/#findComment-787630 Share on other sites More sharing options...
ashrobbins87 Posted March 18, 2009 Author Share Posted March 18, 2009 Ok this is sort of solved now, managed to muddle a solution somehow! The problem now is that it populates the fields if I open the user.php page in the same browser window, but not when I open it in the javascript popup. Link to comment https://forums.phpfreaks.com/topic/149951-reading-from-previous-page-drop-down-list/#findComment-787638 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.