All pastes #2027503 Raw Edit

3/6 (display.php)

public php v1 · immutable
#2027503 ·published 2010-12-23 19:52 UTC
rendered paste body
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>	<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />	<title>Music catalogue</title>	<style type="text/css">	body {		background-color:#000;		font-family:Verdana;		color:#999;	}		table {		border-collapse:collapse;		height:50%;		width:75%;	}		table,td,th {		border:1px solid #999;	}		th {		vertical-align:bottom;		background-color:#999;		color:#000;	}	</style></head><body onload="document.newalbum.artist.focus()">	<form action="insert.php" name="newalbum" method="post">		<label for="artist">Artist: </label><input type="text" name="artist" id="artist" />		<label for="album">Album: </label><input type="text" name="album" id="album" />		<label for="year">Year: </label><input type="text" name="year" id="year" />		<label for="genre">Genre: </label><input type="text" name="genre" id="genre" />		<input type="submit" name="add" value="add" />	</form>	<form action="search.php" name="search" method="get">		<label for="searchartist">Artist: </label><input type="text" name="searchartist" id="searchartist" />		<label for="searchalbum">Album: </label><input type="text" name="searchalbum" id="searchalbum" />		<label for="searchyear">Year: </label><input type="text" name="searchyear" id="searchyear" />		<label for="searchgenre">Genre: </label><input type="text" name="searchgenre" id="searchgenre" />		<input type="submit" name="search" value="search" /><br />		<strong>Sort results by:</strong> <input type="checkbox" name="searchsortartist" value="artist" />artist		<input type="checkbox" name="searchsortalbum" value="album" />album		<input type="checkbox" name="searchsortyear" value="year" />year		<input type="checkbox" name="searchsortgenre" value="genre" />genre	</form>	<table>		<tr>			<th>Artist</th>			<th>Album</th>			<th>Year</th>			<th>Genre</th>			<th></th>		</tr><?phprequire("formvalidator/formvalidator.php"); // include our form validation classsession_start(); // initialize sessionif(isset($_SESSION['username'])&&isset($_SESSION['password'])) { // check to see if session variables are set	/* initialize variables, connect to SQL */	$server="localhost";	$db="music";	$con=mysql_connect($server,$_SESSION['username'],$_SESSION['password']) or die(mysql_error());	mysql_select_db($db,$con) or die(mysql_error());		if(isset($_POST['sort'])) { // check to see if the user has decided to sort the data		$query="SELECT * FROM music_info ORDER BY "; // set up initial query		/* append query if sorting options were set */		if(isset($_POST['sortart']))			$query.="artist,";		if(isset($_POST['sortalb']))			$query.="album,";		if(isset($_POST['sortyear']))			$query.="year,";		if(isset($_POST['sortgen']))			$query.="genre,";		$query=trim($query,"\x2C"); // trim the trailing comma from the query	}	else {		$query="SELECT * FROM music_info ORDER BY artist,year"; // default sorting method	}		$result=mysql_query($query) or die(mysql_error());		while($row=mysql_fetch_array($result,MYSQL_ASSOC)) { // print out results in the form of a nicely formatted HTML table		$artist=$row['artist'];		$album=$row['album'];		$year=$row['year'];		$genre=$row['genre'];		echo "<tr>\n";		echo "<td>".$artist."</td>\n";		echo "<td>".$album."</td>\n";		echo "<td>".$year."</td>\n";		echo "<td>".$genre."</td>\n";		$artist=urlencode($artist);		$album=urlencode($album);		$year=urlencode($year);		$genre=urlencode($genre);		echo "<td><a href=\"delete.php?artist=$artist&album=$album&year=$year&genre=$genre\">remove</a></td>\n"; // automatically generated removal link for any entry in the databse; see delete.php		echo "</tr>\n";	}	mysql_close($con);}else {	echo "</table>\n";	echo "<strong>You must <a href=\"music.php\">log in</a> before you can access the database.</strong><br />\n"; // display log in if session variables aren't set	exit(0);}?>	</table>	<br />	<br />	<strong>Sort by:</strong><br />	<form action="" method="post" name="sort">		<input type="checkbox" name="sortart" value="art" />artist		<input type="checkbox" name="sortalb" value="alb" />album		<input type="checkbox" name="sortyear" value="year" />year		<input type="checkbox" name="sortgen" value="gen" />genre		<input type="submit" name="sort" value="sort" />	</form>	<br />	<br />	<br />	<small><a href="logout.php">logout</a></small></body></html>