By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

Want to get checkbox name

P: 28
Dar all.....
I want to get Check box name in php
my code sample is here.....


if(isset($_POST['delete'])
{
in this place.... How can i get checkbox name????
can i get checkbox name which the user checked??

}
<html>
<form method=POST>
<?php
$query=mysql_query("SELECT id FROM table");
while($result=mysql_fetch_array($query))
{
echo "<input type=checkbox name={$result['id']} >
}
<input type=submit name=delete>

?>
</form>
</html>
Feb 27 '07 #1
Share this Question
Share on Google+
2 Replies


ronverdonk
Expert 2.5K+
P: 4,258
You should know by now that your must enclose any shown code within php or code tags!
Read the Posting Guidelines before you show any more code here!

As for your question: you cannot do it like this in PHP. A checkbox is a client object and cannot be interrogated (DOM-wise) with PHP.

The usual way to handle checkboxes is to give the box a name (or an array name) and let the values be filled by the MySQL result values. After submission you interrogate the POSTed name field or array and extract the values from it. Like the following sample shows:

[php]<?php
if (isset($_POST['submit'])) {
print_r($_POST['checkit']);
exit;
}
?>
<form method="POST" action="a.php">
<input type="checkbox" name="checkit[]" value="1" />
<input type="checkbox" name="checkit[]" value="2" />
<input type="checkbox" name="checkit[]" value="3" />
<input type="submit" name="submit" value="Submit" />
</form>[/php]

Ronald :cool:
Feb 28 '07 #2

P: 28
You should know by now that your must enclose any shown code within php or code tags!
Read the Posting Guidelines before you show any more code here!

As for your question: you cannot do it like this in PHP. A checkbox is a client object and cannot be interrogated (DOM-wise) with PHP.

The usual way to handle checkboxes is to give the box a name (or an array name) and let the values be filled by the MySQL result values. After submission you interrogate the POSTed name field or array and extract the values from it. Like the following sample shows:

[php]<?php
if (isset($_POST['submit'])) {
print_r($_POST['checkit']);
exit;
}
?>
<form method="POST" action="a.php">
<input type="checkbox" name="checkit[]" value="1" />
<input type="checkbox" name="checkit[]" value="2" />
<input type="checkbox" name="checkit[]" value="3" />
<input type="submit" name="submit" value="Submit" />
</form>[/php]

Ronald :cool:
many thz bro.........
Mar 2 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.