dwex Posted August 4, 2010 Share Posted August 4, 2010 This is actually a page to edit the drama details. Database- 3 tables 1. drama dramaID drama_title 1 friends 2. drama_genre drama_genreID dramaID genreID 1 1 2 2 1 1 3 1 3 3. genre genreID genre 1 comedy 2 romance 3 family 4 suspense 5 war 6 horror <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $dbname = 'drama'; $link = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or trigger_error('Error connecting to mysql'); $id = $_GET['dramaID']; $link2 = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or trigger_error('Error connecting to mysql'); $sql2 = "SELECT * from drama , drama_genre , genre WHERE drama.dramaID='".$id."' AND drama_genre.dramaID='".$id."' AND drama.dramaID = drama_genre.dramaID AND drama_genre.genreID = genre.genreID"; $status2 = mysqli_query($link2,$sql2) or die (mysqli_error($link2)); $link3 = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or trigger_error('Error connecting to mysql'); $sql3 = "SELECT * from genre "; $status3 = mysqli_query($link3,$sql3) or die (mysqli_error($link3)); <form method='Post' action='doUpdate.php' enctype="multipart/form-data"> <?php while ($row2 = mysqli_fetch_assoc($status2)) { ?> <td height="1"></td> <td><select name="gdrop"> <option value="<?php echo $row2['genreID'];?>"><?php echo $row2['genre'];?></option> <?php while ($row3 = mysqli_fetch_assoc($status3)) { ?> <option value="<?php echo $row3['genreID'];?>"><?php echo $row3['genre'];?></option> <?php } mysqli_close($link3); ?> <input type='hidden' id='drama_genreID' name='drama_genreID' value = "<?php echo $row2['drama_genreID']; ?>"/> </select> <input type="hidden" id="dramaID" name="dramaID" value = "<?php echo $row['dramaID'];?>"/> <input type="submit" Value="Update"/> The result was there were 3 dropdown menus but only the first dropdown menu has all 6 genres from my database and also the genre that belongs to the drama. I'm also wondering how I can bring all the drama_genreIDs to my save(doupdate.php) page and update all 3 of them because it seems like only the last dropdown menu's data is saved. And also how can I display only 6 genres instead of 7 with the genre that belongs to the drama , being set as the default selection. Link to comment https://forums.phpfreaks.com/topic/209776-how-to-display-multiple-dropdown-menus-from-database-and-save-all-the-data/ Share on other sites More sharing options...
dwex Posted August 4, 2010 Author Share Posted August 4, 2010 $id = $_POST['dramaID']; $dgen = $_POST['drama_genreID']; $genre= $_POST['gdrop']; $link7 = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or trigger_error('Error connecting to mysql'); $query7 = "UPDATE drama_genre SET genreID = '$genre' , dramaID = '$id' WHERE drama_genreID='".$dgen."'"; $result7 = mysqli_query($link7, $query7) or die(mysqli_error($link7)); } mysqli_close($link7); ?> This is how my saving code looks like which I think only saves one out of the three dropdown menu data. Link to comment https://forums.phpfreaks.com/topic/209776-how-to-display-multiple-dropdown-menus-from-database-and-save-all-the-data/#findComment-1095055 Share on other sites More sharing options...
dwex Posted August 4, 2010 Author Share Posted August 4, 2010 need help with this please >.< Link to comment https://forums.phpfreaks.com/topic/209776-how-to-display-multiple-dropdown-menus-from-database-and-save-all-the-data/#findComment-1095122 Share on other sites More sharing options...
dwex Posted August 5, 2010 Author Share Posted August 5, 2010 anyone? Link to comment https://forums.phpfreaks.com/topic/209776-how-to-display-multiple-dropdown-menus-from-database-and-save-all-the-data/#findComment-1095418 Share on other sites More sharing options...
dwex Posted August 5, 2010 Author Share Posted August 5, 2010 nobody knows this? Link to comment https://forums.phpfreaks.com/topic/209776-how-to-display-multiple-dropdown-menus-from-database-and-save-all-the-data/#findComment-1095459 Share on other sites More sharing options...
dwex Posted August 5, 2010 Author Share Posted August 5, 2010 . Link to comment https://forums.phpfreaks.com/topic/209776-how-to-display-multiple-dropdown-menus-from-database-and-save-all-the-data/#findComment-1095522 Share on other sites More sharing options...
Ruzzas Posted August 5, 2010 Share Posted August 5, 2010 I have no idea why you didnt use one table and your $id can be used for sql injection. Link to comment https://forums.phpfreaks.com/topic/209776-how-to-display-multiple-dropdown-menus-from-database-and-save-all-the-data/#findComment-1095526 Share on other sites More sharing options...
dwex Posted August 5, 2010 Author Share Posted August 5, 2010 because one drama and have many genres and vice versa. Link to comment https://forums.phpfreaks.com/topic/209776-how-to-display-multiple-dropdown-menus-from-database-and-save-all-the-data/#findComment-1095532 Share on other sites More sharing options...
dwex Posted August 5, 2010 Author Share Posted August 5, 2010 security of the website doesnt matter too , I just want that to work. Link to comment https://forums.phpfreaks.com/topic/209776-how-to-display-multiple-dropdown-menus-from-database-and-save-all-the-data/#findComment-1095533 Share on other sites More sharing options...
dwex Posted August 5, 2010 Author Share Posted August 5, 2010 oh mine , how come nobody knows this. Link to comment https://forums.phpfreaks.com/topic/209776-how-to-display-multiple-dropdown-menus-from-database-and-save-all-the-data/#findComment-1095623 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.