0

I am trying to accomplish live checkbox result with checked/unchecked checkbox.

My logic for checkbox works but now I want to store this live checkbox result in MYSQL So when I click on checkbox, result should be stored in database same as when I unchecked checkbox result should be stored in database.

I don't want to use any button in this example. I am very close to result just want doing something small mistake. Please help me out. Thank you.

Here is my complete small code:

### Check.php

<!DOCTYPE html>
<html>
    <head>
        <meta charset=utf-8 />
        <title>JS Bin</title>
        <!--[if IE]>
            <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <script type="text/javascript" >
            function writeTo(object) {
                var container = document.getElementById("container");
                if (object.checked) {
                    container.innerHTML =  "Added " + object.value + " <br />";
                } else {
                    container.innerHTML =  "Removed " + object.value + " <br />";
                }
                $.ajax( {
                    url: 'check1.php',
                    method: 'POST',
                    data: { chkvalue: object.value }
                });
            }
        </script>
    </head>
    <body>
        <div id="container"></div>
        <input type="checkbox" onclick="return writeTo(this)" name="check_list" value="Appel">Apple<br>
        <input type="checkbox" onclick="return writeTo(this)" name="check_list" value="Grape">Grape<br>
        <input type="checkbox" onclick="return writeTo(this)" name="check_list" value="Orange">Orange<br>
        <?php
            echo $dd= "<script>document.writeln(container.innerHTML);</script>";
            require 'Database.php';
            echo $sql="Update scott123.rahul_tbl_users set group1='$dd' where Dingoid=70001501";
            //$sql1=mysql_query($sql);
        ?>
    </body>
</html>

###check1.php
<?php
    $value = $_POST['chkvalue'];

    echo $sql="Update scott123.rahul_tbl_users set group1='$value' where Dingoid=70001501";

    $sql1=mysql_query($sql);
?>
Gwenc37
  • 2,064
  • 7
  • 18
  • 22
  • I see at least 1 struggling point : you're not passing any identifier when posting data. You're sending the value of the checkbox, not which checkbox it is – Laurent S. May 15 '13 at 13:25
  • @Bartdude But i am writing it in function.So i thought it might sending value to checkbox as well.Can you please point in the code where should i make changes.Thanks very much – Rahul Deshmukh May 15 '13 at 13:27
  • well, in the data, you're sending object.value , you would need to associate another data like object.id or object.name , or anything allowing you to identify your checkbox once the request reaches the server. I'm not saying it's the only problem, but it's at least one of them. – Laurent S. May 15 '13 at 13:30
  • @Bartdude do you have any small example of this.And my checkbox and other things are working fine.Only thing is i need to get those value in php mysql.Thanks – Rahul Deshmukh May 15 '13 at 13:34
  • What small example ? there's some kind of misunderstanding here... What I say is that I don't see with the data you send how check1.php would know which checkbox was checked or unchecked. Only that some checkbox was checked, which is useless. If you don't see this I'm affraid it will be quite hard to help you further – Laurent S. May 15 '13 at 14:52

1 Answers1

0

Looks like you are trying to put alias on rahul_tbl_users like this scott123.rahul_tbl_users

This is wrong you cannot do that way.

chandresh_cool
  • 11,753
  • 3
  • 30
  • 45