i want to check if a checkbox is checked through a mysql database request. it should be something like this (just a concept code, what of course isnt working) that should work probably with ajax, becouse i dont want to reload all the time:
$ergebnis = $mysqli->query("SELECT text,status FROM checkboxes where id=1 ;");
while($zeile = $ergebnis->fetch_array()) {
echo "<input type=\"checkbox\";
if ({$zeile['status']} == "true") {checked=\"checked\"}
;
echo " name=\"feld\" class=\"checkIt\"/>";
echo " {$zeile['text']}
";
echo "";
}
?>
i have got 3 fields in the database. One text field where the text next to the checkbox shows up, a status field, where the script can see if something is "true" or "false" an a auto incrementation id. I hope you can help me
write this code
$ergebnis = $mysqli->query("SELECT text,status FROM checkboxes where id=1 ;");
while($zeile = $ergebnis->fetch_array()) {
$text = "";
$text .= "<input type=\"checkbox\"";
if ({$zeile['status']} == "true") { $text .= " checked=\"checked\""; }
$text .= " name=\"feld\" class=\"checkIt\"/>";
$text .= "{$zeile['text']}";
echo $text;
//echo "";
}
There are so many errors was present in your code.
$ergebnis = $mysqli->query("SELECT text,status FROM checkboxes where id=1 ;");
while($zeile = $ergebnis->fetch_array()) {
echo '<input type="checkbox"';
if ({$zeile['status']} == "true") { echo ' checked="checked"'; }
echo ' name="feld" class="checkIt" />';
echo $zeile['text'];
}
?>