刷新并提交后,选中复选框

时间:2016-01-30 09:59:04

标签: javascript php jquery checkbox

我试图选中复选框,但在刷新页面后,如果选中该复选框,数据库将更新为“是”,但数据库会自动将其更新为“&”。 #39;无'即使使用local.store检查复选框,我希望有人可以帮助我。这是我的代码。

    <form action="" method="POST">
     <label for="option1">Waarschuwingsbericht inschakelen voordat het volgende pack wordt geopend als jou pack boven de 200.000 waard is?</label><input id='option1' type="checkbox" name="checkbox" value="yes"><br>
      <input type="submit" value="Opslaan en nog een pack openen">
    </form>
<?
    if(isset($_POST['checkbox'])){
        $sql = "UPDATE users SET puntenchecked = 'yes' WHERE username = '" . $usernamez . "'";
        $result = mysql_query($sql) or die('Query failed: ' . mysql_error());
    }
    else {
        $sql = "UPDATE users SET puntenchecked = 'no' WHERE username = '" . $usernamez . "'";
        $result = mysql_query($sql) or die('Query failed: ' . mysql_error());
    }
?>
<script>
$(function(){
    var test = localStorage.input === 'true'? true: false;
    $('input').prop('checked', test || false);
});

$('input').on('change', function() {
    localStorage.input = $(this).is(':checked');
    console.log($(this).is(':checked'));
});
</script>

2 个答案:

答案 0 :(得分:2)

试试这个:

 $data = Items::whereRaw("item_name like '%$term%'")
     ->take(15)->select('item_name')->distinct()->get();

 $result = $data->groupBy('item_name');

 return $result;

答案 1 :(得分:1)

替换以下JS逻辑:

{{From::textarea('comment','',array('placeholder=>'put your comment here'))}}

检查更多here