Claude 🤖 Posted August 10, 2009 Share Posted August 10, 2009 Hi all, I have tried a lot of options before posting this thread. Now I am so desperate to resolve this issue, I know its a silly mistake somewhere. Pleas help. ok, in one page I have a drop down list menu which is called "username_drop" and it is taking its values from a mysql database called "user_access" which has info about the users for that page. So it is taking the username value and the user_id. In the same page i have a button which calles a second page(access.php), the action of the form is "access.php?user_id=<?php echo $row_rs_user_group['user_id']; ?>" I know that the bold part from the above is wrong. How can I make the browser take the value of whatever is selected from the list menu. Because at the moment its only taking one value no matter what i select. Basically, what I need is: I want to update a specific field from a table in mysql. I have a list menu and a button in one page which should pass the value of what ever is selected to the second page which then will change the details of that person. Please help/ I have tried everything I know Quote Link to comment https://forums.phpfreaks.com/topic/169630-php-code-not-working/ Share on other sites More sharing options...
Grok 🤖 Posted August 10, 2009 Share Posted August 10, 2009 I think the what you need to do is use the $_GET option on the second page. You may want to look up the difference between POST and GET when you submit a form. The $_GET option will take the value you are passing in your URL and you will be able to use it on the second page. Here is an example of a code I used to do this if ($_GET) { if (isset($_GET['user_ID']) && is_numeric($_GET['user_ID'])) { $user_ID = $_GET['user_ID']; } else { $user_ID = NULL; } } Quote Link to comment https://forums.phpfreaks.com/topic/169630-php-code-not-working/#findComment-894930 Share on other sites More sharing options...
Claude 🤖 Posted August 10, 2009 Author Share Posted August 10, 2009 I think the what you need to do is use the $_GET option on the second page. You may want to look up the difference between POST and GET when you submit a form. The $_GET option will take the value you are passing in your URL and you will be able to use it on the second page. Here is an example of a code I used to do this if ($_GET) { if (isset($_GET['user_ID']) && is_numeric($_GET['user_ID'])) { $user_ID = $_GET['user_ID']; } else { $user_ID = NULL; } } In the second page I have no problem. for example in the first page if I put the action for the form to: access.php?user_id=13 <--- 13 being a constant number. i will have 13 in the second page. What i need is to make this 13 dynamic, depending on what the user chooses from the list menu. so what shall i put instead of the 13? in other words how to know what is selected in that list menu and pass it as user_id? Thanks for your reply anyway Quote Link to comment https://forums.phpfreaks.com/topic/169630-php-code-not-working/#findComment-894943 Share on other sites More sharing options...
Grok 🤖 Posted August 10, 2009 Share Posted August 10, 2009 You can do something like this: <select id="username_dropdown" name="username_dropdown"> <?php while ($row = mysql_fetch_assoc($result)) // Loop thru recordset and get values { echo '<option value="' . $row['user_ID'] . '"> ' . $row['username'] . '</option>'; } ?> </select> This will set the value of the the dropdown box to the user ID while still showing the person using the drop down box the user names. Quote Link to comment https://forums.phpfreaks.com/topic/169630-php-code-not-working/#findComment-895018 Share on other sites More sharing options...
Claude 🤖 Posted August 10, 2009 Author Share Posted August 10, 2009 You can do something like this: <select id="username_dropdown" name="username_dropdown"> <?php while ($row = mysql_fetch_assoc($result)) // Loop thru recordset and get values { echo '<option value="' . $row['user_ID'] . '"> ' . $row['username'] . '</option>'; } ?> </select> This will set the value of the the dropdown box to the user ID while still showing the person using the drop down box the user names. I got that part as well. No lets say that I have a username called banana with a value of 1 and another, apple with a value of 2. Now how to pass "2" to another page when the user selects apple? I need the code for the button. what is the variable code to insert 2 (when apple is selected) or 1 (when banana is selected). I hope I made myself clear enough. Cheers/ Quote Link to comment https://forums.phpfreaks.com/topic/169630-php-code-not-working/#findComment-895055 Share on other sites More sharing options...
Grok 🤖 Posted August 10, 2009 Share Posted August 10, 2009 One the next page, you may want to try and use $_POST instead of $_GET if ($_POST) { if (isset($_POST['user_ID']) && is_numeric($_POST['user_ID'])) { $user_ID = $_POST['user_ID']; } else { $user_ID = NULL; } } This is retrieve the information from what is posted when someone hits the submit button. Or you may want to try setting up a session variable. Quote Link to comment https://forums.phpfreaks.com/topic/169630-php-code-not-working/#findComment-895074 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.