JavaScript和数据存储在数据库中

时间:2015-04-02 20:15:22

标签: javascript mysql

这里我提供的代码,其中数据需要存储在MySQL数据库中,来自JavaScript文件。

脚本文件代码

 function set_shield(t_value){
           var ok = confirm("Are you sure want Lock Value?")
                                if (ok)
                                {
                                    xmlhttp.open("GET","p_scripts/dataStore.php?set_value="+shield.value,true);
                                    xmlhttp.send();
                                    window.location.reload(true);
                                    }                           
                        }

我的dataStore.php代码包含如下:

 <?php
   session_start();
   $set_value=$_GET[set_value];
   include("php_scripts\db.php"); // connection create here
   $date =date("Y-m-d H:i:s");
   mysql_query("Update user SET p1='y' WHERE  user_id='$_SESSION[login_user]'");
   mysql_query("INSERT power_play (user_id, p_play_type, date_of_play, set_value) VALUES ('$_SESSION[login_user]','1','$date','$set_value')");

    ?>

2 个答案:

答案 0 :(得分:0)

我认为您的Insert查询不正确。  试试这个:

   INSERT into power_play (user_id, p_play_type, date_of_play, set_value)
        VALUES ('$_SESSION[login_user]','1','$date','$set_value')");

答案 1 :(得分:0)

在客户端尝试使用以下内容

var xhr = new XMLHttpRequest();
xhr.open("GET", p_scripts/dataStore.php?set_value="+shield.value,true);
xhr.send();