Javascript fullcalendar脚本调用GET php变量来获取mysql数据';行不通

Javascript fullcalendar脚本调用GET php变量来获取mysql数据';行不通,javascript,php,mysql,fullcalendar,Javascript,Php,Mysql,Fullcalendar,我对此代码有问题: <?php // Require DB Connection require_once('connect.php'); // Get ALl Event $er = 1; $sth = $dbh->prepare("SELECT * FROM events WHERE id_user = $er AND events.date BETWEEN ? AND ? ORDER BY events.date ASC"); $sth->execut

我对此代码有问题:

<?php
// Require DB Connection
require_once('connect.php');
// Get ALl Event
$er = 1;
$sth = $dbh->prepare("SELECT * FROM events WHERE id_user = $er AND events.date BETWEEN ? AND ? ORDER BY events.date ASC");
$sth->execute(array($_GET['start'], $_GET['end']));
$result = $sth->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($result);
?>

谢谢大家,解决方案是:

在main.js中添加此函数以获取URL数据:

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
    results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  }
在这些活动中:

// Get all events stored in database
        events: 'crud/getEvents.php',
    events: 'crud/getEvents.php?cu='+getParameterByName('cu'),
因此,在文件getEvents中,我们可以调用变量:

// Get ALl Event
$er = $_GET['cu'];
$sth = $dbh->prepare("SELECT * FROM events WHERE id_user = $er AND events.date BETWEEN ? AND ? ORDER BY events.date ASC");

你的页面是如何被调用的?$u GET['cu']来自哪里?我在您的代码中没有看到它,在您使用的URL中也没有看到任何相关内容。请用一个例子说明你在使用itAlso<代码>其中id\u user=$er。。。
$er
应替换为一个参数,并移动到传递给“execute”的数组中。您需要参数化所有传入值,而不仅仅是其中的一部分。非常感谢大家。我将项目上传到此url,这样您就可以完整地看到它:ADyson,$\u GET['cu']来自此页面的链接,当您转到日历时,url看起来像此urlhttp://..path../?cu=1 使用cu变量。您仍然需要参数化$er变量properlyP.S。所有“getParameterByName”正则表达式和其他复杂性都可以通过使用。