Happy New Year everyone.
I am a novice at both PHP and javascripts, so please bear with me a little and no flames.
In my website, I would like to run a DB query and display the results based on the client side time. So my PHP script would have to be modified to bring in the date and month values using a call to a javascript. Below are the portions of my code. Please tell me where I am going wrong.
The initial assignments in the PHP script (trying only with the month first):
[php]/* Init Block /
/ $todayMN = date(“m”); /
$todayDN = date(“d”);
/ Pradeep. Dec. 27, 2014: Getting the date and time from client side for DB query /
$todayMN = ‘’;
/ $todayDay = ‘’; */[/php]
The javascript:
currentTime = new Date()
month = currentTime.getMonth()
month = month + 1;
if (month < 10){
month = “0” + month;
}
document.write(month);
Later in the PHP script:
[php]//** Family Born this day.
function getBirthToday($targs) {
global $people_table, $sLstr, $bPlaceLen, $bDayHeader, $URLpath, $todayMN, $todayDN, $sPerson;
$cacheName = ‘tngBornToday.cache’;
/* Pradeep. Dec. 27, 2014: Getting the date and time from client side for DB query */
print $todayMN . " day " . $todayDN;
//** Pradeep May 17, 2014
//** Added "living" to the query below.
$qry = "
SELECT personID,firstname,lastname,birthdate,birthplace,gedcom,living,YEAR(birthdatetr) AS lYear
FROM $people_table
WHERE" . $treeInsert . "
month(birthdatetr) = $todayMN
AND dayofmonth(birthdatetr) = $todayDN $sLstr ORDER BY lYear
";
$results = qryDB($qry);[/php]
The “qryDB” function is:
[php]//** Query Database
function qryDB($qry) {
global $link;
$result = mysql_query($qry) or die (“Query ERROR: $qry”);
return $result;
}[/php]
Issue:
When this code is run with the month determined by the PHP code, the results are just fine. However, when the assignment comes from the javascript, it returns an error from the “qryDB” function, thusly:
Query ERROR: SELECT personID,firstname,lastname,birthdate,birthplace,gedcom,living,YEAR(birthdatetr) AS lYear FROM tng_people WHERE month(birthdatetr) =01 AND dayofmonth(birthdatetr) = 01 ORDER BY lYear
The assignments for the month and the year are as expected, yet the DB query does not work.
Looking in the logs for the DB server, I see the following:
150101 14:15:45 12 Connect @on
12 Query SET NAMES utf8
12 Init DB
12 Query SELECT userID FROM tng_users
12 Quit
7 Init DB
7 Query SELECT * FROM tng_mediatypes ORDER BY ordernum, display
7 Query SELECT languageID, display, folder FROM tng_languages ORDER BY display
7 Query SELECT personID,firstname,lastname,birthdate,birthplace,gedcom,living,YEAR(birthdatetr) AS lYear
FROM tng_people
WHERE
month(birthdatetr) =
AND dayofmonth(birthdatetr) = 01 ORDER BY lYear
So, what goes into the DB for query is the call of the javascript. However, all the debug statements, and even the error message, says the assignment is correct.
What am I doing wrong? Thank you in advance.