pip_r Posted November 8, 2009 Share Posted November 8, 2009 Hi, I'm trying to pass a variable from a form menu to another page. The menu items have been populated via an sql query to a mysql database. The query works as the drop down menu displays all the tutor names. The problem is that when I select a surname, the variable is not passed, but rather it takes the default value of 'select'. The code below shows I also try to pass hidden variables (gained from the earlier sql query) and these are passing over to the next page fine. I can't see why the value of the menu item is not passing. Cheers for any help with this - it's driving me nuts..! Pip Coding from page 1 // Code to connect to database - this is working fine // Perform sql query to get various details from database - again working fine echo "Use the drop down menu to select a tutor"; echo "<form method = 'post' action = 'page.php'>" echo "<select name='id'>"; echo "<option value = 'select'>Select Tutor</option> // Perform sql query to get specific tutor details from database - working fine while ($row='mysql_fetch_array($result)) { $id = $row["id"]; $surname = $row["surname"]; echo "<option value = ' " . $id . " ' >" . $surname . "</option>"; } echo "</select>"; echo "<input type='hidden' name='school' value = '$school' /> echo "<input type='hidden' name='code' value = '$code' /> echo "input type = 'image' src='../images/submit.png' /> echo "</form> Coding from beginning of page 2 - showing whether variables have passed $id = $_POST['id']; $school = $_POST['school']; $code = $POST['code']; echo "id is $id<br>school is $school<br>code is $code."; Quote Link to comment https://forums.phpfreaks.com/topic/180747-problem-passing-variables-from-mysql-populated-form-menu/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 8, 2009 Share Posted November 8, 2009 When you do a "view source" of the form page in your browser, what do you get for the <option values? If the form is correct, you would need to post your whole actual form processing code if you want someone to determine what it is doing that is causing the problem. Best guess, you have an if() statement that is assigning the value 'select' to the variable instead of comparing the variable with the value 'select' (i.e. using one = (an assignment operator) instead of two == (an equal comparison operator.) Quote Link to comment https://forums.phpfreaks.com/topic/180747-problem-passing-variables-from-mysql-populated-form-menu/#findComment-953615 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.