I have in my table from database 3 rows of tinyint type which are called: option1,option2,option3. I want to assing them value to variables $int1,$int2,$int3. + I have in my script 3 checkboxes and I want to check if checkboxes value is equal with checkboxes value from database. For example: if checkbox1 is checked && checkbox2 is checked, in above if, if checkbox1 value == $int1 && checkbox2 value == $int2, I don't know how to make this in my script, can anybody help me? I don't put the script here because I don't have any checkbox in it.
2 Answers
Not exactly sure what you want to do? As there's no script for me to work from. This is what I got from your description.
if($_POST&&isset($_POST['submit'])/*submit button*/){
$DBH=new mysqli('location','user','pass','database');
$get=$DBH->prepare('SELECT option1,option2,option3 FROM table');
$get->execute();
$get->bind_result($int1,$int2,$int3);//bearing in mind that I think you have one record in this table?
$get->close();
if($int1==int$_POST['checkbox1']&&$int2==int$_POST['checkbox2']&&$int3==int$_POST['checkbox3'])echo'All match';
else echo'Something didn\'t match.';
}
There's ultimately 1000's of ways of doing what you want to do. I'm not sure what you want to do so I've guessed :p Hope it gives you some insight into what you're trying to achieve.
<?php
$DBH=new mysqli('location','user','pass','database');
$get=$DBH->prepare('SELECT option1,option2,option3 FROM table');
$get->execute();
$get->bind_result($int1,$int2,$int3);
$get->close();
?>
<input type="checkbox" name="int1" value ="value1" <?php echo ($int1=="value1")?"checked:'checked'":"";?>/>
<input type="checkbox" name="int2" value ="value2" <?php echo ($int1=="value1")?"checked:'checked'":"";?>/>
<input type="checkbox" name="int3" value ="value3" <?php echo ($int3=="value3")?"checked:'checked'":"";?>/>
Hope this helps