0

Been trying to work this out for hours

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?>"> <?php 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']?>"> <?php 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>

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

2
Contributors
6
Replies
8
Views
7 Years
Discussion Span
Last Post by szkoda
0

Could you run this script and post the output?

<?
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);

?>
<pre>
<?
print_r($row);
?>
</pre>
0

I ran the exact code you posted and it just came up with a blank screen

0

I ran the exact code you posted and it just came up with a blank screen

If you view the source, you'll probably see something like this:

<pre></pre>

This means that your SQL statement is returning nothing from the database. Since the database returned nothing, then there would be nothing to put into the form areas.

The form area inserts are correct in code, it's just that the $row array is empty.

If you want to double check, add this line directly after the print_r statement:

$myelements = count($row);
echo $myelements;

This should output the number of elements in your array. If the number is zero, then the mysql statement is the problem.

0

The number 1 is printed with that code you gave me. I have multiple entries in each table, I cant see how it can be wrong?

0

FIXED! I had to change the data type of the 'Genres' column in the film table to Integer as it was initially set to varchar

Thanks for the help :)

Edited by szkoda: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.