View Single Post
Old 10-10-2012, 05:19 PM   PM User | #3
Wilhelmina
New to the CF scene

 
Join Date: Oct 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Wilhelmina is an unknown quantity at this point
Thank you Old Pedant for your reply!

I would prefer having the edit on the same page though because once clicked the form for adding a new movie will change to a replicate of the form but with the details of the movie clicked to edit already in place. Could i not use the action attribute in the form to a seperate script where the UPDATE will take place? (Sorry, as you might have noticed I'm quite new to this.) Here is what the code looks like now:

PHP Code:
<?php // movielibrary.php
require_once 'login.php';
$query "SELECT * FROM library";
$result mysql_query($query);
if (!
$result) die ("Database access failed: " mysql_error());
$rows mysql_num_rows($result);

echo 
"<table border='1'><tr> <th>Title</th><th>Director</th>
    <th>Year</th><th>Category</th><th>Update</th><th>Delete</th></tr>"
;

for (
$j $j $rows ; ++$j)
{
    
$row mysql_fetch_row($result);
    echo 
"<tr><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td>
    <td><a href='movielibrary.php?edit=$row[0]'>Edit</a</td><td><a href='movielibrary.php?delete=$row[0]'>Delete</a></td></tr>"
;
}

echo 
"</table>";

if(isset(
$_GET['edit']))
{
echo <<<_END
<form action="update.php" method="post">
Choose a category:<br />
<input type="hidden" name="id" value="$row
[0]" />
<input type="radio" name="category" value="$row
[4]" />Thriller<br />
<input type="radio" name="category" value="$row
[4]" />Romantic<br />
<input type="radio" name="category" value="$row
[4]" />Swedish<br />
<input type="radio" name="category" value="$row
[4]" />Animated<br />
<input type="radio" name="category" value="$row
[4]" />Comedy<br /><br />
   Title <input type="text" name="title" value="$row
[1]" /><br />
Director <input type="text" name="director" value="$row
[2]" /><br />
    Year <input type="text" name="year" value="$row
[3]" /><br />
         <input type="submit" value="CHANGE" />
</form>
_END;
}

elseif(isset(
$_GET['delete'])){
   
$delete $_GET['delete'];
   
$query mysql_query("DELETE FROM library WHERE id='$row[0]'")or die(mysql_error());
   
header("Location: movielibrary.php"); 
}

else
{
echo <<<_END
<form action="store.php" method="post">
Choose a category: <br />
<input type="hidden" name="id" />
<input type="radio" name="category" value="Thriller" />Thriller<br />
<input type="radio" name="category" value="Romantic" />Romantic<br />
<input type="radio" name="category" value="Swedish" />Swedish<br />
<input type="radio" name="category" value="Animated" />Animated<br />
<input type="radio" name="category" value="Comedy" />Comedy<br /><br />
   Title: <input type="text" name="title" /><br />
Director: <input type="text" name="director" /><br />
    Year: <input type="text" name="year" /><br />
         <input type="submit" value="STORE" />
</form>
_END;
}

mysql_close($db_server);
?>
How can I get the values from the row with the id in the edit link to show in the edit form?

Thanks beforehand,
Wilhelmina
Wilhelmina is offline   Reply With Quote