Jump to content

how to get row data from checkbox


jamesreno20

Recommended Posts

  i have checkbox in a table and want to put the value as the id in the database then when i press submit it displays all the row data for each checkbox 
 
$res = pg_query ($conn, "SELECT artist,composer,genre,title,album,label,price,description FROM music");
echo "<table border='1'>";
echo "<tr><th>Select</th><th>Artist</th><th>Composer</th><th>Genre</th><th>Title</th><th>Album</th><th>Label</th><th>Price</th><th>Description</th></tr>";
 while ($row = pg_fetch_row($res)) 
 {
 echo "<tr>";
 echo '<td><input type="checkbox" name="check_list[]" value="' . $row['res'] .'"></td>';
 for ($column = 0; $column < pg_num_fields($res); $column++) 
 {
 echo "<td>" . $row[$column] . "</td>";
 }
 echo "</tr>";
 }
 echo "</table>\n";
 
________________________________________________--
basket.php
 
echo "<table border='1'>";
echo "<tr><th>Select</th><th>Artist</th><th>Composer</th><th>Genre</th><th>Title</th><th>Album</th><th>Label</th><th>Price</th><th>Description</th></tr>";
 
echo "<pre>\n";
print_r($_POST['check_list']);
echo "</pre>\n";

 

Link to comment
https://forums.phpfreaks.com/topic/292602-how-to-get-row-data-from-checkbox/
Share on other sites

There is no column "res" in your results (you didn't select one with that name or use it as an alias) so $row['res'] has no value.

 

Select the id  along with the other columns and use that as the value.

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.