A beginner in this area, I have been able to read a record from a
MySQL database and populate an HTML form (wow!). Now, my goal is to
allow the user to edit the contents of the form and then update the
record in MySQL.
The problem is, as soon as the "Update" button (type="submit") is
pressed, all of the data disappear from the form. How can that be
prevented?
Here is my code:
<body>
<?php
// Select the Music database
mysql_select_db("music") or die("Could not connect to Music
database");
// Perform SQL query
$sql = "select * from cdcollection where Artist = '$txtArtistSearch'";
$result = mysql_query($sql) or die("SQL Select failed");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
?>
<?php
if ($cmdUpdate) {
// Select the Music database
mysql_select_db("music") or die("Could not connect to Music
database");
$sql = "UPDATE cdcollection SET Notes='$txtNotes' WHERE Artist =
'$txtArtistSearch'" ;
$result = mysql_query($sql) or die("SQL Update failed");
}
?>
<form method="post" action="<?php echo $PHP_SELF;?>">
<p>Artist
<input type="text" name="txtArtist" size="19" value="<?php echo
$row['Artist'] ?>"> </p>
<p>Title
<input type="text" name="txtTitle" size="39" value="<?php echo
$row['Title'] ?>"></p>
<p>Genre
<input type="text" name="txtGenre" size="13" value="<?php echo
$row['Genre'] ?>"></p>
<p>Rating
<input type="text" name="txtRating" size="3" value="<?php echo
$row['Rating'] ?>"></p>
<p>Notes
<input type="text" name="txtNotes" size="84" value="<?php echo
$row['Notes'] ?>"></p>
<p>
<input type="button" value="Search" name="cmdSearch">
<input type="submit" value="Update" name="cmdUpdate"></p>
</form>
</body>
</html>
Thanks!!
Mark Jones