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

时间:2016-10-23 15:23:44

标签: javascript php checkbox

我有这张桌子 table
我想要何时检查复选框以插入(或更新)到post_check数据库字段中,并选中与复选框对应的值或未选中(未提交按钮)。 我写了这段代码,但是我被困了很长时间因为值没有传递到数据库,勾号没有留在复选框中(即使我用header()函数重新加载)

<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>

0 个答案:

没有答案