Jump to content

Archived

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

vickytam

Checkbox post value to another page

Recommended Posts

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

Share this post


Link to post
Share on other sites
You use a single form and list the 10 records within it.

Give the checkboxes values = id of each record

Put '[]' at end of checkbox names so they get posted as arrays

[code]<form name="input" action="test2.php" method="get">
<table border="1">

<?php
while ($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]

Share this post


Link to post
Share on other sites

×

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.