Basically, I want to update MySql table corresponding to each checkbox. Here is a schema of my requirement:
I have uploaded files in sql and placed four checkboxes next to each of the files picked up from database[displayed on the web](read, write, download, share). Also, I have four additional columns in database (readFlag, WriteFlag, DownloadFlag, ShareFlag). What I want is, suppose I check the 'read' checkbox next to a particular file, I want to update the readFlag next to that particular file name and not any other file. Similarly for other checkboxes and files as well.
I have written a code for updating the readflag manually, which is working perfect, but it's not working when working with checkboxes. Any suggestions would be of great help. Thanks.
Here is the code I have written so far: I have manually set readFlag to 1 just to check incase in assignMainPage.php.
PHP :
<?php
$host = 'localhost';
$user = '';
$password= '';
$db = 'user_information';
@$conn = mysql_connect($host, $user, $password) or die(mysql_error());
mysql_select_db($db, $conn);
if(!$conn) {
    echo "Connection to the database failed";
}
$result = mysql_query("SELECT * FROM user_files ORDER BY id ASC");   
?>
Jquery :
<script>
$(function() {
    $(".assign").click(function() { 
        var check = $(this).closest('tr').find('input:checkbox');
        var fileID = $(this).closest('tr').find('.file_id').val();
        var element = $(this);
        var assign_id = element.attr("id");
        var assigninfo = 'id=' +assign_id;
        if(confirm("assign")) { 
            $.ajax({
                type: "POST",
                url: "assignMainPage.php",
                data: assigninfo,
                success: function(){
                }
            });
            alert("file id : " + fileID);
        }
    });
});
assignMainPage.php
<?php
$host = 'localhost';
$user = '';
$password= '';
 $db = 'user_information';
@$conn = mysql_connect($host, $user, $password) or die(mysql_error());
mysql_select_db($db, $conn);
if(!$conn) {
     echo "Connection to the database failed";
 }
if($_POST['id']) {
$id = mysql_real_escape_string($_POST['id']);
 $assign = "UPDATE user_files SET readFlag = 1 where id = '$id'";
mysql_query($assign);
}
?>
HTML :
<div class="container">
<?php
while($row = mysql_fetch_array($result)){
    $id1 = $row['id'];
    $name = $row['user_file_name'];
?>
<?php
if(isset($_POST['assign']) && $_POST['assign'] == '$id1') { 
    echo("success");
}
?>
<div class="show">
<table width = "80%"  align = "center">
<tr class="trclass">
<td width= "15%"><span class="name"><?php echo $name; ?> <> <?php echo $id1;?>       </span></td>
<input type="hidden" value="<?php echo $id1; ?>" class="file_id" />
<td width="15%">
    <span class="action"><input type="button" id="<?php echo $id1; ?>" class="delete"  title="Delete" value="Delete <> <?php echo $id1;?>"></span>
</td>
<td width= "10%"><span class="action">
    <input type="checkbox" id="<?php echo $id1; ?>" class="read" title="read">Read <> <?php echo $id1;?></span>
</td>
<td width= "15%"><span class="action"><input type="checkbox" id="<?php echo $id1; ?>" class="write" title="write">Write <> <?php echo $id1;?></span></td>
<td width= "15%"><span class="action"><input type="checkbox" id="<?php echo $id1; ?>" class="download" title="download">Download <> <?php echo $id1;?></span></td>
<td width= "15%"><span class="action"><input type="checkbox" id="<?php echo $id1; ?>" class="share" title="share">Share <> <?php echo $id1;?></span></td>
<td width= "15%">
     <span class="action">
        <input type="submit" id="<?php echo $id1; ?>" name="assign" class="assign" title="assign" value="Assign <> <?php echo $id1; ?>">
     </span>
</td>
</tr>
<table>
</div>
<?php
}
?>
 
     
    