Hi guys, I really need help with this one...have spent 3 hours trying to figure it out...
Basically, I have 3 tables necessary for this function to work (the query and PHP)... Authors, Books and Users.
An author can have many books, and a user can have many books - that's it.
When the admin user selects to update a book, they are presented with a form, displaying the current data within the fields, very straight forward... However there is one tricky part, the admin user can change the author for a book (incase they make a mistake) and also change the user for which the book is associated with.
When I select to update the single book information I am not getting any values what so ever for author_id or user_id. Meaning that when the user updates the book info, the associations with the user and author is being scrapped altogether (when before there was an association)... I cannot see why this is happening because I can clearly see the IDs for the users and authors for my option values (this is because they are in select dropdowns). Here is what my sql to retrieve the user ID is:
SELECT user_id, name FROM users
and then i have my select options which brings up all the users in the system:
<label>This book belongs to:</label> <select name="name" id="name">
<option value="<?php echo $row['user_id']?>" SELECTED><?php echo $row['name']?> - Current</option>
<?php
while($row = mysql_fetch_array($result))
{ ?> <option value="<?php echo $row['user_id']; if (isset($_POST['user_id']));?>"><?php echo $row['name']?></option>
<?php } ?>
In the presented HTML form, I can select the users (by name) and within the source code I can see the IDs (for the value) matching against the names of the users.
Finally, in my script that performs the update, I have this:
$book_id = $_POST['book_id'];
$bookname = $_POST['bookname'];
$booklevel = $_POST['booklevel'];
$author_id = $_POST['author_id'];
$user_id = $_POST['user_id'];
$sql = "UPDATE books SET bookname= '".$bookname."', booklevel= '".$booklevel."', author_id='".$author_id."', user_id= '".$user_id."' WHERE book_id = ".$book_id;
The result of this query returns no value for either author_id or user_id... Obviously in this question I have given the information for the user stuff (with the HTML being displayed) but im guessing that I have the same problem with authors aswell... How can I get these ID's passed to the script so that the change can be acknowledge!! :(