javascript - 使用php将ajax数据发送到mysql
问题描述
我实现了以下 javascript 函数来收集数据并显示它们,但我需要将这些数据保存到 mysql 数据库中以跟踪数据,我尝试使用下面的 php 代码在本地连接到 mysql 但没有用,我认为问题是我不知道如何收集数据并将它们插入到查询中
这是javascript代码:
function Script2()
{
var player = GetPlayer();
$.ajaxSetup({ cache: false });
$.ajax({
url: "data.php",
type: "GET",
processData: true,
data: {"entry.939953095" :player.GetVar("username"),
"entry.391274481" :player.GetVar("Slide1"),
"entry.822772676" :player.GetVar("slide2"),
"entry.934389578" :player.GetVar("slide3"),
"entry.1669272782" :player.GetVar("slide4"),
"entry.1486049396" :player.GetVar("Slide5"),
"entry.264581670" :player.GetVar("slide6"),
dataType: "jsonp",
success: function (data) {
processData(data);
}
});
用于连接数据库并存储数据的 php 文件
<?php
if(isset($_REQUEST))
{
$connect_error='sorry we\'re experincing connection error';
@mysql_connect('localhost','root','') or die($connect_error);
mysql_select_db('lo-test') or die($connect_error);
error_reporting(E_ALL && ~E_NOTICE);
$data=$_GET['player.GetVar("Slide1")'];
$sql="INSERT INTO lo-test(text2) VALUES ('$data')";
$result=mysql_query($sql);
}
?>
对我的代码以及如何使用 Get 或 Post 处理变量的任何建议
解决方案
你会得到这样的数据
$data = $_GET['entry.939953095'];
或者您也可以尝试转储$_GET
变量并查看它拥有的所有键
推荐阅读
- python - 如何拥有一个包含数千个表的数据库,这些表具有不同数量的列,这些列在 Django / SQLAlchemy ORM 中都是同一个类?
- html - 如何使用 html 和 css 创建一个类似 facebook 的下拉菜单?
- python - 无法启动 instapy
- javascript - React - 从父/兄弟组件触发子方法的最佳方式
- c# - Unity 2D 中的视频播放器播放音频但在处于非活动状态后设置为活动时不显示视觉效果
- powershell - 将新别名附加到别名的别名
- java - Kubernetes 上微服务之间集群间通信的最佳方式?
- javascript - 承诺所有猫鼬找到返回不完整的值
- java - 如何在Java中拆分括号和
- css - :nth-child(1) 不工作 - 使用 html 示例