0

Why am I getting this type of error in this string:

$query="SELECT Name,Lastname FROM $_SESSION['SESS_MAIN_BASE'] s,
     WHERE s.FK_ID_user={$id_user}
     AND DATE(s.time) BETWEEN '".$d_year1."-".$d_month1."-".$d_day1."' AND '".$d_year2."-".$d_month2."-".$d_day2."'";
1
  • Remove teh quotes from the array keys. When using arrays in a double-quoted string, the quoted keys will issue warnings. That or switch to the {} encapsulation notation. Commented Oct 19, 2012 at 17:44

4 Answers 4

8

Replace

 $query="SELECT Name,Lastname FROM $_SESSION['SESS_MAIN_BASE'] s,

With

$query="SELECT Name,Lastname FROM {$_SESSION['SESS_MAIN_BASE']} s,

Better Still

$query= "SELECT Name,Lastname FROM %s s, WHERE s.FK_ID_user= '%d' AND DATE(s.time) BETWEEN '%d-%d-%d' AND '%d-%d-%d'";
$query = sprintf($query,$_SESSION['SESS_MAIN_BASE'],$id_user,$d_year1 ,$d_month1,$d_day1,$d_year2,$d_month2,$d_day2);
Sign up to request clarification or add additional context in comments.

6 Comments

I am still getting error on this place: WHERE s.FK_ID_user= ''
I checked that I am receiving a number as value $id_user but error still persists
With %d I am getting only 0 (zero)
What is the value of var_dump($_SESSION['SESS_MAIN_BASE'])
That has nothing to do with the question or error above .... PHP string is giving syntax error
|
1

Change

$_SESSION['SESS_MAIN_BASE']

to

{$_SESSION['SESS_MAIN_BASE']}

$_SESSION is becoming blank because the [] is a string.

Comments

0

Try this:

$query="SELECT Name,Lastname FROM {$_SESSION['SESS_MAIN_BASE']} s, ";
$query.="WHERE s.FK_ID_user={$id_user}";
$query.="AND DATE(s.time) BETWEEN '".$d_year1."-".$d_month1."-".$d_day1."' AND";
$query.="'".$d_year2."-".$d_month2."-".$d_day2."'";

1 Comment

Pointless. This changes nothing and just makes things a little harder to read. I won't -1 since you did put in the {}, which will fix the problem.
0
$query="SELECT Name,Lastname FROM $_SESSION['SESS_MAIN_BASE'] s,
     WHERE s.FK_ID_user=$id_user
     AND DATE(s.time) BETWEEN '$d_year1-$d_month1-$d_day1' AND '$d_year2-$d_month2-$d_day2'";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.