hoj78
September 9th, 2008, 12:12 AM
Hi All,
I have been making a page to display records from a music database, I have a page that displays music by genre with a hyperlink to display all tracks from that genre with a checkbox, the artist name and the title. I need the user to be able to select multiple tracks and press a "add to playlist" button that stores the selection which can be emailed to the site owner. I have pasted the code below that displays all tracks from a genre with a checkbox for each. I guess I need to know what the best way to do it is.
<?php require_once('Connections/dbconn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_Recordset1 = "-1";
if (isset($_GET['genre'])) {
$colname_Recordset1 = $_GET['genre'];
}
mysql_select_db($database_dbconn, $dbconn);
$query_Recordset1 = sprintf("SELECT recordID, artist, title FROM tblrecord WHERE genre = %s ORDER BY artist ASC", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $dbconn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!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>Untitled Document</title>
</head>
<body>
<form id="add_to_cart" name="add_to_cart" method="post" action="music-display.php">
<table width="68%" border="0" cellspacing="0" cellpadding="0">
<?php do { ?>
<tr>
<td width="3%"><label>
<input type="checkbox" name="recordID[]" id="checkbox" />
</label></td>
<td width="29%"><?php echo $row_Recordset1['artist']; ?></td>
<td width="68%"><?php echo $row_Recordset1['title']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table><br />
<label>
<input type="submit" name="addToCartbtn" id="addToCartbtn" value="Add to my playlist" />
</label>
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
I have been making a page to display records from a music database, I have a page that displays music by genre with a hyperlink to display all tracks from that genre with a checkbox, the artist name and the title. I need the user to be able to select multiple tracks and press a "add to playlist" button that stores the selection which can be emailed to the site owner. I have pasted the code below that displays all tracks from a genre with a checkbox for each. I guess I need to know what the best way to do it is.
<?php require_once('Connections/dbconn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_Recordset1 = "-1";
if (isset($_GET['genre'])) {
$colname_Recordset1 = $_GET['genre'];
}
mysql_select_db($database_dbconn, $dbconn);
$query_Recordset1 = sprintf("SELECT recordID, artist, title FROM tblrecord WHERE genre = %s ORDER BY artist ASC", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $dbconn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!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>Untitled Document</title>
</head>
<body>
<form id="add_to_cart" name="add_to_cart" method="post" action="music-display.php">
<table width="68%" border="0" cellspacing="0" cellpadding="0">
<?php do { ?>
<tr>
<td width="3%"><label>
<input type="checkbox" name="recordID[]" id="checkbox" />
</label></td>
<td width="29%"><?php echo $row_Recordset1['artist']; ?></td>
<td width="68%"><?php echo $row_Recordset1['title']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table><br />
<label>
<input type="submit" name="addToCartbtn" id="addToCartbtn" value="Add to my playlist" />
</label>
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>