Using Ajax to store checkbox in database
<p>Update: The code is working. I had an incorrectly named table in my php file.</p>

<p>I have the following that I've found from some snippets during my searches for help however I cannot get it to work. What I am trying to accomplish is clicking a check box and it automatically populate a row in my database that I can refer to on any other page. Right now when I click the checkbox, nothing happens.</p>

<p>HTML</p>

<pre><code>&lt;td&gt;&lt;input type="checkbox" name="&lt;?php echo $brow['WorkOrder']; ?&gt;"  value="&lt;?php echo $brow['WorkOrder']; ?&gt;"&gt;&lt;/td&gt;
</code></pre>

<p>Ajax</p>

<pre><code>     &lt;!-- Checkbox storage --&gt;
     &lt;script&gt;
     $(document).ready(function(){
        $("input[type='checkbox']").on('click', function(){
        var checked = $(this).attr('checked');
        if(checked){
            var value = $(this).val();
            $.post('functions/checkBox.php', { value:value }, function(data){
                // data = 0 - means that there was an error
                // data = 1 - means that everything is ok
                if(data == 1){
                    // Do something or do nothing :-)
                    alert('Data was saved in db!');
                }
            });
        }
        });
    });
    &lt;/script&gt;
</code></pre>

<p>functions/checkBox.php</p>

<pre><code>&lt;?php
if ($_POST &amp;&amp; isset($_POST['value'])) {

    // db connection
    include("../../db.php");

    // sanitize the value
    $value = mysql_real_escape_string($_POST['value']);

    // start the query
    $sql = "INSERT INTO TemporaryCheckBoxID (WorkOrder) VALUES ('$value')";

    // check if the query was executed
    if(mysql_query($sql)){
       // everything is Ok, the data was inserted
       print(1);    
    } else {
       // error happened
       print(0);
    }
}
?&gt;
</code></pre>