1

This is a follow up question to my previous question in here. PHP - Dropdown menu(select) not working properly to while loop

I follow the code given to me and I think it is working correctly. But my only concern is that, the query in my code is actually for the shelf table, and not for the book table which have the foreign key for the shelf. Here is my code for the textfield. It is in a form which have a button that redirects to check_book.php to add it

<div class="form-group">

      <label for="inputEmail" class="col-lg-2 control-label">Shelf</label>
      <div class="col-lg-10">
    <?php   
    $sel_admin = "select * from shelf";
    $rs_admin = mysql_query($sel_admin);
    echo '<select class="form-control">';
    while($row = mysql_fetch_array($rs_admin))
                {

                echo"<option value='" .$row['shelf_id']."'>" . $row['shelf_description'] ."</option>";
                }
                echo'</select>';
                ?>
      </div>
    </div>

It's giving me this error Notice: Undefined index: shelf_id in C:\xampp\htdocs\OCatalog\admin\check_book.php on line 8 but the other non-foreign key textfield is just fine.

And here is my check_book.php

$book_id = $_POST['book_id'];
    $book_title = $_POST['book_title'];
    $author_id = $_POST['author_id'];
    $book_quantity = $_POST['book_quantity'];
    $shelf_id = $_POST['shelf_id'];

How can I view all the shelf then adding it as a foreign key?

PS. The select is also in the form which when i click the submit button it will go to check_book.php

1 Answer 1

0

You forgot to put a name attribute in your select

echo '<select class="form-control" name="shelf_id">';
Sign up to request clarification or add additional context in comments.

2 Comments

Hey yeah the error goes down to 1 error. But it says that thebook_id is undefined variable? I check my other forms and Im pretty sure i just copy it but it can add well without declaring the _id
Sorry man, I forgot to mark your answer as correct. Yes, this is the method I used. my concern is just it doesn't read the auto_increment book_id to which i have already been solved by adding a hidden textfield. Kudos!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.