Jump to content

Form problem: Getting info from one table to insert into another table


Go to solution Solved by maxxd,

Recommended Posts

I have a form to submit information about weekend retreats to a database, one of which is location. I have a lookup table for locations so the user can select from a list.  The Locations table has a Primary Key called Location_ID and the Weekends table has a Foreign Key called Location_ID_FK.

I'm having trouble saving the Location_ID (from a query) to Location_ID_FK.  This is the query to select the location:

Quote

<div class="form-group">
       <label for="Location" class="col-sm-4 control-label">Location</label>
        <div class="col-sm-10">
             <select name="std" class="form-control col-sm-8">  
             <?php   
                   $query = "SELECT * FROM locations";
                    if ($result = $conn->query($query)) {  
                      while ($row = $result->fetch_assoc()) {
                      echo "<option value=".$row["Location_ID"].">".$row["Location_Name"]."</option>";
                       } 
                    }
               ?>
               </select>
           </div>  
 </div> 

This in itself works, I get the list of locations.
But when I try to submit the form  I keep getting the message "Warning: Undefined array key "Location_ID"..."
I've tried everything I can think of, including changing the name of the field Location_ID_FK to Location_ID, I've also tried putting this line after the 'while' statement.
 

Quote

 $Location_IK_FK = $row["Location_ID"];

I've also tried adding this same line in the section defining variables to be inserted.

I should add that when I use a simple input text for Location the insert query works, and I've triple-checked that I'm using the correct variable in the insert query.

What am I missing?  Any help is gratefully appreciated.

Edited by singingsands
add more information

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.