skygremlin Posted May 2, 2013 Share Posted May 2, 2013 Issue: I’m missing something with my code to receive values from 2 different drop down menus from another form via post. Description: I have a php page with 2 drop down menues. These are populated from a MySql DB: location and jobtype. I’m trying to send the selected values from each to a new form to run a query. My first test is to make sure I'm getting the values, then I can code that to a query, but it looks like I'm only getting the last value. Below is the code on the sending from the form and the receiving php page. Also the error I’m seeing. I’m pretty new at this (a couple weeks or so) so I’m sure this is something simple I’m missing.. thanx Sending form: <form action="job_listing.php" method="post" > <table id="structure"> <tr> <td id="navigation"> <h4>Search Job Openings:</h4> Location: <br /> <?php //Get the data from DB $location_set = get_all_jobinfo(); //Actual query: SELECT location as location, jobtitle as jobtitle FROM jobs; if(!$location_set){ die("Database query Failed: " . mysql_error()); } echo "<select name='location'>"; //Loop thru the array and get the 'location' value while ($location = mysql_fetch_array($location_set)){ echo "<option value='" . $location['location'] . "'>" . $location['location'] . "</option>"; } echo "</select>" ?> <br /> <br /> Job Title: <br /> <?php $jobtitle_set = get_all_jobinfo(); //Actual query: SELECT location as location, jobtitle as jobtitle FROM jobs; if(!$jobtitle_set){ die("Database query Failed: " . mysql_error()); } echo "<select name='location'>"; //Loop thru the array and get the 'location' value while ($jobtitle = mysql_fetch_array($jobtitle_set)){ echo "<option value='" . $jobtitle['jobtitle'] . "'>" . $jobtitle['jobtitle'] . "</option>"; } echo "</select>" ?> </p> <input type="submit" name="submit"/> </td> <td id="page"> <h1>Adding text</h1> </td> </tr> </table> </form> Receiving PHP page <td id="page"> <?php /* Get imported values */ if(!isset($_POST['location'])){ echo "Location is not set"; echo "<br />"; }else { $location = $_POST['location']; echo "Location: " . $location; echo "<br />"; } if(!isset($_POST['jobtitle'])){ echo "Job Title is not set"; echo "<br />"; }else { $jobtitle = $_POST['jobtitle']; echo "Job Title: " . $jobtitle; echo "<br />"; } ?> </td> Result: Is attached image Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted May 2, 2013 Share Posted May 2, 2013 Both of your selects have the same name="location". The second one will overwrite the first in the POST array. They should have different names. Quote Link to comment Share on other sites More sharing options...
Solution skygremlin Posted May 2, 2013 Author Solution Share Posted May 2, 2013 insert a bit of foul language...... thank you... Quote Link to comment 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.