I want to be able to update my database in order to change some dynamic content on my site which contains movie reviews.
First Step I need to be able to select which movie review I want to update by selecting it from a dropdown menu which is dynamically populated by the database.
The second step is to populate a set of forms which related to the movie that was selected from the dropdown box so the information can be edited.
The third step is to then run an update query to alter the databse.
This is the code I have written to populate the dropdown menu with the movie titles stored in the database which is working.
<form action="" method="POST">
<select name="title">
<option value="">Select Movie Title</option>
<?php
$sql="SELECT * FROM review ORDER BY title ASC";
$result=mysql_query($sql);
while ($row=mysql_fetch_assoc($result)) {
echo "<option value=" . $row['title'] . ">" . $row['title'] . "</option>";
}
echo"</select>";
?>
<input type="submit" name="select" value="Select">
I am having trouble in figuring out how to populate the forms which will display the inforamtion related to the dropdown selection.
<?php
if(isset($_POST['select'])){
$query = mysql_query("SELECT * FROM REVIEW WHERE title = '$title'");
while ($fetch=mysql_fetch_assoc($query)){
?>
<p>Title:<input type="text" size="35" name="title" value="<?php echo $_POST['title']; ?>"></p>
<p>Source:<input type="text" size="35" name="source" value="<?php echo $_POST['source']; ?>"></p>
<p>Rating:<input type="text" size="5" name="rating" value="<?php echo $_POST['rating']; ?>"></p>
Review:<br>
<textarea name="review" cols="40" rows="7">
<?php echo $_POST['review']; ?>