Jump to content

Check Boxes - mulitple with same name


nz4y45

Recommended Posts

Hello, I have the following code, I would like to be able to capture each individual checkbox that is selected, as of right now, only the first is captured because the checkboxes have the same "name".  Thanks for any help!

 

$link = mysql_connect('host', 'id, 'pw);

mysql_select_db('db', $link);

 

$sql = "select * from ChangeControl order by Client, SDate";

$result = mysql_query($sql);

 

 

$tdcount = 1;

$numtd = 1; // number of cells per row

echo "<form action=\"CC_test.php\">";

echo "<table border='1'>";

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

if ($tdcount == 1) echo "<tr>";

if (stristr ($row[8], "Yes")) $status='Closed';

else $status='Open';

 

echo "<td><input type=\"checkbox\" name=\"checkbox\" value='$row[1]'><b>Ticket #:</b> $row[1] <b>Client:</b> $row[6] <b>Start Date:</b> $row[2] <b>End Date:</b> $row[3]<br><b>Description:</b> $row[7]"; // display as you like

if ($tdcount == $numtd) {

echo "</tr>";

$tdcount = 1;

} else {

$tdcount++;

}

}

// time to close up our table

if ($tdcount!= 1) {

while ($tdcount <= $numtd) {

echo "<td> </td>";

$tdcount++;

}

echo "</tr>";

}

echo "</table>";

echo "<input type=\"submit\" name=\"submit\" value=\"Send Daily Report\">";

 

echo "</form>";

 

 

Link to comment
https://forums.phpfreaks.com/topic/145562-check-boxes-mulitple-with-same-name/
Share on other sites

So, I think I'm having some of the same problems as others with Arrays.

 

I have my array now, and I can print it out on screen, but I would like to store the data in seperate rows in my database?

 

I have tried numerous things, and I can get only the last checkbox selected to enter?

 

thanks in advance

This is how i'm gathering the data:

 

$link = mysql_connect('host', 'id, 'pw);

mysql_select_db('db', $link);

 

$sql = "select * from ChangeControl order by Client, SDate";

$result = mysql_query($sql);

 

 

$tdcount = 1;

$numtd = 1; // number of cells per row

echo "<form action=\"CC_test.php\">";

echo "<table border='1'>";

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

if ($tdcount == 1) echo "<tr>";

if (stristr ($row[8], "Yes")) $status='Closed';

  else $status='Open';

 

echo "<td><input type=\"checkbox\" name=\"checkbox\" value='$row[1]'><b>Ticket #:</b> $row[1] <b>Client:</b> $row[6] <b>Start Date:</b> $row[2] <b>End Date:</b> $row[3]<br><b>Description:</b> $row[7]"; // display as you like

if ($tdcount == $numtd) {

echo "</tr>";

$tdcount = 1;

} else {

$tdcount++;

}

}

// time to close up our table

if ($tdcount!= 1) {

while ($tdcount <= $numtd) {

echo "<td> </td>";

$tdcount++;

}

echo "</tr>";

}

echo "</table>";

echo "<input type=\"submit\" name=\"submit\" value=\"Send Daily Report\">";

 

echo "</form>";

 

This is how I print out the array,

 

<?

if(isset($_POST['checkbox']))

{

print '<pre>';

// print_r($_POST['checkbox']);

// print '</pre>';

print 'Send daily reports for the following change records?: ';

echo "<br>";

// You wanted to loop.

foreach($_POST['checkbox'] as $value)

{

// print $value . ' ,';

echo $value."<br>";

 

 

 

}

}

?>

 

Now, I just need to be able to seperate the array values into seperate database rows.

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.