I'm testing a form with checkboxes, with the values extracted from mysql database with a query. Everthing works fine with the population from the query.
But when submit the form, I only get the first part of the value.

I am populating the checkbox values the album names e.g Joshua Tree Rattle and Hum, but the value which are return are Joshua and Rattle.

Here is the code I am using, I am a newbie to PHP.

php include 'sub_folder/mp3.php';?>

<?php include 'sub_folder/funtions.php';?>

// add header for web page

add_header("Please Choose Albums");

// Connect to database

mysql_connect("$hostname_mp3","$username_mp3","$password_mp3") or die (mysql_error());

mysql_select_db("$database_mp3") or die (mysql_error());

// set Variable to U2 (just for testing)

$artist = "u2";

// set query to Variable

$sql2 = mysql_query("SELECT DISTINCT album  FROM mp3s Where artist = '$artist' ORDER by album;


// output form with check boxes with values from database.

$html = '<br><br> <div align="center" ><form action="result-test.php" method="post">';

$html .= '<p>Select Albums for play list:</p>';

while($row = mysql_fetch_array($sql2)){

$album = $row['album'];

$html .= '<INPUT NAME= "result[]" TYPE= "CHECKBOX" VALUE='.$album.'> '.$album.'<BR>';


$html .= '<input type=submit value = "Submit Your Choice"></form></div>';

$html .= '</body>';

//$album = $value["album"];

echo $html;


The page it outputs to is result-test.php is as follows:-

  $album = $_POST['result'];
    echo("You didn't select any albums.");
    $N = count($album);

    echo("You selected $N albums(s): ");
    for($i=0; $i < $N; $i++)
      echo($album[$i] . " " );
      echo '<br />';

Any help will be welcome.

Recommended Answers

All 2 Replies

Usually this means that you don't have the variable in quotes in the form so it only picks up the text up to the first space.


Thanks for the reply, it works fine now, I have included the quotes as you suggested.



Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.