Jump to content

Send multiple checkbox data to new page and display


Remote Control

Recommended Posts

Hi All,

 

Hoping I can get some help with the following problem, I have db with a music list that is displayed with SQL query onto a .php page. I want a user to select music tracks with a checkbox(s) and add the selection to a "play list". I then would like them to be able to email the playlist to the site owner for later use.

 

So far I have the list of music displaying on page but cannot work out how to pass the info from the check boxes to a new page and display the artist and title that have been selected.

 

I have posted a URL of an example that I am working towards.

 

http://www.feelgoodevents.com.au/music1.php

 

Any help would be appreciated

you have to make a loop to create checkboxes. as value of the checkbox you have to declare the key of each record. Of course this loop has to reside in a form so you can send your checkbox values for processing after OK or submit button.

 

because you dont know how many checkboxes a visitor is going to check, you have to transmit an array list. check example 3 of this link http://gr2.php.net/variables.external

 

hope i helped.

Hi Snk,

 

Yeah I understand that I need to send it in an array to be displayed on the new page, this is the code that lists all music for a genre with a check box next to each title. Sorry for all the code

 

<?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);
?>

 

And this is the code that I wrote for the selection the user makes, I think I am on the right track but not quite there.

<?php
if(isset($_POST['add_to_cart'])) {
$artist = $_POST['artist'];
$title = $_POST['title'];

if (isset($_POST['check_sound'])) {

foreach($_POST['recordID']  as  $recordVal)  {
$record_id .= " $recordVal";
} 

} else {

//nothing was checked...
$record_id = 'nothing was checked';
}
}
?>

<!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>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
  <td>Record ID</td>
    <td>Artist</td>
    <td>Title</td>
    </tr>
  <tr>
  	<td><?php echo $recordID['recordID']; ?></td>
    <td><?php echo $artist['artist']; ?></td>
    <td><?php echo $title['title']; ?></td>
    </tr>
</table>

</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.