vickytam Posted April 12, 2006 Share Posted April 12, 2006 Dear all,I wrote some code as below:<?php…… (Connected to database & get 10 records from database (using array function)$name = $row['name'];$id = $row['id']; ?><form name="input" action="test2.php" method="get"><table border="1"><tr><td><?php echo $name; ?></td><td><?php echo $id; ?></td><td><input type="checkbox" name="check" value ="1">Record checked<br><td><input type="checkbox" name="del" value ="1">Delete?<br></tr></table><input type="submit" value="Submit"></form>There are 10 records were loaded via array function.Would you help to tell me how can I post the value to "test2.php" when I clicked the checkbox.Thank you.Vicky Link to comment https://forums.phpfreaks.com/topic/7168-checkbox-post-value-to-another-page/ Share on other sites More sharing options...
Barand Posted April 12, 2006 Share Posted April 12, 2006 You use a single form and list the 10 records within it.Give the checkboxes values = id of each recordPut '[]' at end of checkbox names so they get posted as arrays[code]<form name="input" action="test2.php" method="get"><table border="1"><?phpwhile ($row = mysql_fetch_array($result)) { $name = $row['name']; $id = $row['id'];?> <tr> <td><?php echo $name; ?></td> <td><?php echo $id; ?></td> <td><input type="checkbox" name="check[]" value ="<?php echo $id; ?>">Record checked<br> <td><input type="checkbox" name="del[]" value ="<?php echo $id; ?>">Delete?<br> </tr><?php}?></table><input type="submit" value="Submit"></form>[/code]To process[code]echo "These ids were checked<br>";foreach ($_GET['check'] as $checkedid) echo "$checkedid<br>";echo "<br>These ids were checked for deletion<br>";foreach ($_GET['del'] as $delid) echo "$delid<br>";[/code] Link to comment https://forums.phpfreaks.com/topic/7168-checkbox-post-value-to-another-page/#findComment-26091 Share on other sites More sharing options...
vickytam Posted April 12, 2006 Author Share Posted April 12, 2006 Thank you. Link to comment https://forums.phpfreaks.com/topic/7168-checkbox-post-value-to-another-page/#findComment-26097 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.