1

i am having problem in printing the values of the different checkbox with the same name & different values..

PHP

//$infect_type=array();
$infect_type = isset($_POST['infect_type']) ? $_POST['infect_type'] : null;

$values= implode(",",$infect_type);
print_r($values);

HTML

<input type="checkbox" name="infect_type" value="Blood Born" /> 
<input type="checkbox" name="infect_type" value="Air Born" />

i can only get the value which is selected last before submitting.

2 Answers 2

1

Use array notation for checkboxes names:

<input type="checkbox" name="infect_type[]" value="Blood Born" /> 
<input type="checkbox" name="infect_type[]" value="Air Born" />

In this case $_POST['infect_type'] is going to be an array of checked values.

Sign up to request clarification or add additional context in comments.

Comments

0

HTML

<input type="checkbox" name="infect_type[]" value="Blood Born" /> 
<input type="checkbox" name="infect_type[]" value="Air Born" />

PHP

<?php
        $infect_type = $_POST['infect_type'];
        foreach ($infect_type as $i) {
                echo $i;
                //Change the code here
        }
?>

This will do.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.