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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
dwex Posted August 4, 2010 Author Share Posted August 4, 2010 need help with this please >.< Quote Link to comment Share on other sites More sharing options...
dwex Posted August 5, 2010 Author Share Posted August 5, 2010 anyone? Quote Link to comment Share on other sites More sharing options...
dwex Posted August 5, 2010 Author Share Posted August 5, 2010 nobody knows this? Quote Link to comment Share on other sites More sharing options...
dwex Posted August 5, 2010 Author Share Posted August 5, 2010 . Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.