Darkmatter5 Posted June 9, 2008 Share Posted June 9, 2008 Here's my textbox code <input name="surveys" type="text" tabindex="10" /> Here's my dropdown list code <?php include 'library/dbconfig.php'; include 'library/opendb.php'; $query="SELECT county_id, county FROM byrnjobdb.counties ORDER BY county ASC"; $result=mysql_query($query); echo "<select id='surveys_county' method='get' tabindex='12'>"; echo "<option>---Select---</option>"; while ($row=mysql_fetch_array($result)) { $r1=$row['county_id']; $r2=$row['county']; echo "<option value='$r1'>$r2</option>"; } echo "</select>"; include 'library/closedb.php'; ?> Here's the submissions button code <input name="addsurvey" type="submit" id="addsurvey" value="Submit new data" tabindex="11" /> Here's the code executed when the button is pressed <?php if(isset($_POST['addsurvey'])) { include 'library/dbconfig.php'; include 'library/opendb.php'; //insert data into table $insertdata="INSERT INTO byrnjobdb.surveys (survey, county_id) VALUES ('" .$_POST['surveys']. "', '" .$_POST['surveys_county']. "')"; /*mysql_query($insertdata) or die(mysql_error() .": $insertdata"); echo $_POST[$survey]. " ADDED to surveys table...";*/ echo "surveys: " .$_POST['surveys']. "<br>"; echo "county: " .$_POST['surveys_county']; include 'library/closedb.php'; } ?> Now when I run the code I get the output of: surveys: xxxx county: Why does it not output: surveys: xxx county: 2 or whatever county ID the user selects. And yes the counties table is populated with counties, it's not empty. Any ideas? Link to comment https://forums.phpfreaks.com/topic/109424-help-with-unexplained-output-dropdown-list/ Share on other sites More sharing options...
kenrbnsn Posted June 9, 2008 Share Posted June 9, 2008 You're problem is occurring because the form is being sent via the GET method and you are checking the $_POST array. Either check the $_GET array or change <?php echo "<select id='surveys_county' method='get' tabindex='12'>"; ?> to <?php echo "<select id='surveys_county' method='post' tabindex='12'>"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/109424-help-with-unexplained-output-dropdown-list/#findComment-561285 Share on other sites More sharing options...
Darkmatter5 Posted June 9, 2008 Author Share Posted June 9, 2008 I did the following and it's still giving me the same output. I only changed the dropdown list. <?php include 'library/dbconfig.php'; include 'library/opendb.php'; $query="SELECT county_id, county FROM byrnjobdb.counties ORDER BY county ASC"; $result=mysql_query($query); echo "<select id='surveys_county' method='post' tabindex='12'>"; echo "<option>---Select---</option>"; while ($row=mysql_fetch_array($result)) { $r1=$row['county_id']; $r2=$row['county']; echo "<option value='$r1'>$r2</option>"; } echo "</select>"; include 'library/closedb.php'; ?> Link to comment https://forums.phpfreaks.com/topic/109424-help-with-unexplained-output-dropdown-list/#findComment-561385 Share on other sites More sharing options...
Barand Posted June 9, 2008 Share Posted June 9, 2008 your select has no name attribute. $_POST['xxxx'] references the field name, not the id. PS I've always set the method in the form tag, not the select tag. Link to comment https://forums.phpfreaks.com/topic/109424-help-with-unexplained-output-dropdown-list/#findComment-561508 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.