Jump to content

Trouble transferring data via post to new form for query


skygremlin
Go to solution Solved by skygremlin,

Recommended Posts

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

post-149783-0-92872500-1367510992_thumb.png

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.