checkbox - How to use && opertor with checkboxes in php
Solution:
Demo: http://phpfiddle.org/main/code/0aix-4tdb
<form method="post" action="">
<span>Select languages</span><br/>
<input type="checkbox" name='lang[]' value="PHP"> PHP <br/>
<input type="checkbox" name='lang[]' value="JavaScript"> JavaScript <br/>
<input type="checkbox" name='lang[]' value="jQuery"> jQuery <br/>
<input type="checkbox" name='lang[]' value="Angular JS"> Angular JS <br/>
<input type="submit" value="Submit" name="submit">
</form>
<?php
if(isset($_POST['submit'])){
if(!empty($_POST['lang'])) {
foreach($_POST['lang'] as $value){
echo $value.'<br/>';
}
}
}
?>
Answer
Solution:
you don't have to use &&
in the 3rd isset()
.
isset() will return true only if all arguments to isset()
are set and do not contain null
So instead of doing,
if(isset($firstname && $lastname)){
$sql = "SELECT firstname,lastname from biodata";
$stmt = $pdo->query($sql);
}
do,
if(isset($firstname , $lastname)){
$sql = "SELECT firstname,lastname from biodata";
$stmt = $pdo->query($sql);
}
For further details, you can visit PHP isset() with multiple parameters
Source