Jump to content

Where am I going wrong


szkoda

Recommended Posts

Been trying to work this out for hours  :confused:

 

I have two tables called 'Genres' and 'Films'. Genres contains two columns 'Genre_id' and 'Genre_Name'. Films contains a load of columns, the most important being 'Title', 'Year', Director', 'Genres'. Now im trying to create a page where the user can edit a film in the 'Films' table. I want this form to already be populated with the existing values which the user can then delete and enter new ones. Heres the code:

 


<?
include 'connect.php';
$FilmID= $_GET['id'];
$result = mysql_query("SELECT Films.*, Genres.Genre_id, Genres.Genre_Name FROM Films INNER JOIN Genres ON Films.Genres = Genres.Genre_id WHERE Films.Film_id = $FilmID" ,$linkme) or die ('Error: '.mysql_error ());

$row = mysql_fetch_array($result);
$current_Genre = $row['Genre_Name'];
$current_Genre_id = $row['Genre_id'];

?>
<form method="post" action="update2.php?id=<? echo $FilmID ?>">
<table>
<tr>
<td>Title</td>
<td><input name = "Title" value="<? echo $row['Title'] ?>" type="text" /></td>
</tr>
<tr>
<td>Year</td>
<td><input name = "Year"  value="<? echo $row['Year'] ?>" type="text" /></td>
</tr>
<tr>
<td>Director</td>
<td><input name = "Director"  value="<? echo $row['Director'] ?>" type="text" /></td>
</tr>
<tr><td>
  Genre:</td><td> <select name="Genre">
  <option value = "<?php echo  $current_Genre_id ?>"> <?  echo  $current_Genre  ?> </option>
<? 
$result = mysql_query("SELECT * FROM Genres",$linkme)  or die ('Error: '.mysql_error ());
while($row = mysql_fetch_array($result));
{ ?>
<option value = "<?php echo  $row['Genre_id'] ?>"> <?  echo  $row['Genre_Name']  ?> </option>
<? } ?>
</select></td>
</tr>
</table>
<input name="Update" type="submit" value="Update" />
</form>
<?
include 'close.php';
?>
<a href = "../admin.php">Back</a>

 

and heres the second page that actually changes the values:

 


<? 
include 'connect.php';
$Title = $_REQUEST["Title"];
$Year = $_REQUEST["Year"];
$Director = $_REQUEST["Director"];
$Genre = $_REQUEST["Genre"];
$FilmID = $_GET['id'];

$result = mysql_query("UPDATE Films SET Title = '$Title' , Year = '$Year', Director ='$Director', Genre ='$Genre' WHERE Film_id = '$FilmID'",$linkme);
include 'close.php';
?>
Record Updated<br />
<a href = "../admin.php">Back</a>

 

There are no errors, the values just dont show up in the form, Where am I going wrong???

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.