Jump to content


Photo

Checkbox post value to another page


  • Please log in to reply
2 replies to this topic

#1 vickytam

vickytam
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 12 April 2006 - 05:25 AM

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

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 12 April 2006 - 06:24 AM

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

<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>

To process

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>";

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 vickytam

vickytam
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 12 April 2006 - 06:53 AM

Thank you.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users