douji6735 2016-10-23 15:23
浏览 30

将复选框中的值发送到SQL DB而不提交按钮

I have this table
table
and I want when to check a checkbox to insert(or update) into the post_check database field with the values checked or unchecked (without submit button) corresponding to the checkbox. I wrote this code, but I have been stuck for a long time because the values didn't pass to database, the tick mark didn't stay in checkbox (even if I made reload with header() function)

<form action="" method="post">                    
 <table class="table table-bordered table-hover"  id="pinakas">
    <thead>
        <tr>
            <th class="titlos"><input style="margin-left: 3px;" type="checkbox" name="checkboxAllBoxes" id="checkboxAllBoxes "></th>
            <th class="titlos">POST_ID</th>
        <th class="titlos">ΚΑΤΗΓΟΡΙΑ</th>
        <th class="titlos">ΤΙΤΛΟΣ</th>                        
            <th class="titlos">ΚΕΙΜΕΝΟ</th>                                            
            <th class="titlos">FILE</th>
            <th class="titlos">ΕΚΔΟΤΗΣ</th>
            <th class="titlos">ΗΜΕΡ.</th>
            <th class="titlos">UPDATE</th>
            <th class="titlos">DELETE</th>
     </tr>                       
    </thead>                      
        
    <?php  
       
       global $connect;
       $query="SELECT * FROM posts ORDER BY post_date DESC ";
       $select_posts= mysqli_query($connect, $query); 
       while($row=  mysqli_fetch_assoc($select_posts)) {
       $post_id=$row['post_id'];
       $post_cat_title=$row['post_cat_title'];
       $post_title=$row['post_title'];
       $post_keimeno=  substr($row['post_keimeno'], 0, 60);
       $post_publisher=$row['post_publisher'];
       $post_image=$row['post_image'];
       $post_date=$row['post_date'];
       $post_check=$row['post_check'];         
       
       echo "<tr>";?>
    
    <td><input type='checkbox' name="checkbox" id="<?php echo $post_id;  ?>" value="<?php echo  $value;  ?>" onchange="check(this);"  ></td>;
       
       <?php
       echo "<td class='keli'><strong>$post_id</td>";
       echo "<td class='keli'>$post_cat_title</td>";
       echo "<td class='keli'>$post_title</td>";
       echo "<td class='keli'>$post_keimeno</td>";
       echo "<td><img src='../images/$post_image' height='50' witdth='50'></td>";
       echo "<td class='keli'>$post_publisher</td>";
       echo "<td class='keli'>$post_date</td>";
       ?>
       <td><a href="tables.php?source=tables&update=<?php echo $post_id; ?>">UPDATE</a></td>
       <td><a href="tables.php?source=tables&delete=<?php echo $post_id; ?>">Delete</a></td>
       </tr>
       <?php
        }            
    ?>                    
    
    </table>
</form>
            
    <div class="button">  
        <!--<button class="koumpi" type="submit" name="submit">SUBMIT</button>-->
        <button type="submit" name="delete"class="btn btn-primary">Delete</button>
        <button type="submit" class="btn btn-primary" name="update" style="background-color: green;">UPDATE</button>
        <button type="submit" class="btn btn-primary">Submit Button</button>
        
    </div>
    
<!--/.row-->  
     <!--/.main-->                  

        <script>
        function check(ch){
            if(ch.checked){
                window.location.href = "tables.php?source=tables&checkbox="+ch.id+"&value=checked";
                //windows.location.replace("http://yahoo.com");
                
            }
            else{
                window.location.href = "tables.php?source=tables&checkbox="+ch.id+"&value=unchecked";
              
            }
        }
        
    </script>

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ogg dd trandata 报错
    • ¥15 高缺失率数据如何选择填充方式
    • ¥50 potsgresql15备份问题
    • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
    • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
    • ¥60 pb数据库修改与连接
    • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
    • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
    • ¥20 神经网络Sequential name=sequential, built=False
    • ¥16 Qphython 用xlrd读取excel报错