Reputation: 29
im having problems with this code:
<?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);
?>
When i past the variable $er
with this value works perfect! but when i pass a $_GET['cu']
fails, someone can tell me what is happened?
Note: $_GET['cu']
is a value that i take from the URL http://..../?cu=1
And this file is calling from a js script of Fullcalendar in the events:
// Get all events stored in database
events: 'crud/getEvents.php',
Upvotes: 0
Views: 150
Reputation: 29
Thank everyone, the solution was:
to the main.js add this function to get the URL data:
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, " "));
}
and in the events:
events: 'crud/getEvents.php?cu='+getParameterByName('cu'),
so in the file getEvents we can call the variable:
// 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");
Upvotes: 1