Jump to content

Checkbox post value to another page


vickytam

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
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.