Ok im unsure where to put my mysql_close();
and i need help cleaning up the script if anyone can help me out that would be great 🙂
can someone kind enough to point out where i should put its????
<html>
<body>
<?php
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("databasename",$db);
if ($submit) {
// here if no ID then adding else we're editing
if ($id) {
$sql = "UPDATE albums SET artistname='$artistname',albumname='$albumname',tracklist='$tracklist',genre='$genre' WHERE id=$id";
} else {
$sql = "INSERT INTO albums (artistname,albumname,tracklist,genre) VALUES ('$artistname','$albumname','$tracklist','$genre')";
}
// run SQL against the DB
$result = mysql_query($sql);
echo "Record updated/edited!<p>";
} elseif ($delete) {
// delete a record
$sql = "DELETE FROM albums WHERE id=$id";
$result = mysql_query($sql);
echo "$sql Record deleted!<p>";
} else {
// this part happens if we don't press submit
if (!$id) {
// print the list if there is not editing
$result = mysql_query("SELECT * FROM albums",$db);
while ($myrow = mysql_fetch_array($result)) {
printf("<a href=\"%s?id=%s\">%s </a> \n \n ", $PHP_SELF, $myrow["id"], $myrow["artistname"]);
printf("<a href=\"%s?id=%s\">%s </a> \n", $PHP_SELF, $myrow["id"], $myrow["albumname"]);
printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["id"]);
}
}
?>
<P>
<a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>
<P>
<form method="post" action="<?php echo $PHP_SELF?>">
<?php
if ($id) {
// editing so select a record
$sql = "SELECT * FROM albums WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$id = $myrow["id"];
$artistname = $myrow["artistname"];
$albumname = $myrow["albumname"];
$tracklist = $myrow["tracklist"];
$genre = $myrow["genre"];
// print the id for editing
?>
<input type=hidden name="id" value="<?php echo $id ?>">
<?php
}
?>
Band Name:<input type="Text" name="artistname" value="<?php echo $artistname ?>"><br>
Album Name:<input type="Text" name="albumname" value="<?php echo $albumname ?>"><br>
Track List: <textarea wrap=physical name="tracklist" cols=60 rows=10><?php echo $tracklist ?></textarea><br>
Genre:<input type="Text" name="genre" value="<?php echo $genre ?>"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
}
?>
</body>
</html>
Had to edit so script would work right..