Jump to content

Session variable not working when producing a kml


boa03eas

Recommended Posts

Hi everybody,

 

I’d be grateful if anybody could provide a little help with this problem.

 

I have a php file that outputs a kml file which is displayed with Google Maps on the website I am working on. I would like a different kml file to be produced depending on the id of the user who has logged onto the website. The data for the kml file is stored on a server database, and is referenced using a user id that I call as a session variable:

 

mysql_select_db($db_name, $db); 		
$userid=$_SESSION[userid];

$query = "SELECT * FROM Weiruedits WHERE userid = " . $userid;

 

All the code to produce the kml file seems to work fine; it’s worked perfectly well on another database which wasn’t been queried by user id.

 

In this current problem set up however, a kml is produced lacking the data for the markers. If the session variable is replaced with an actual user id number (e.g. $userid = 24;), the query works and the kml is produced.

 

I first thought there was a problem with the syntax of my query. However, I am pretty certain this is not the case. I looked up a variety of ways to deal with php variables in SQL queries, and had no problems getting them to work. Yet none of them worked if the session variable was involved.

 

So then I thought the problem lay with the session variable. But testing it I found it brought the correct value.  Strangely, if the code to produce the kml is duplicated, and the last three lines which outputs the kml deleted;

 

$kmlOutput = $dom->saveXML();

header('Content-type: application/vnd.google-earth.kml+xml');

echo $kmlOutput;

 

the MySQL query works fine. The syntax of the query is correct, the session variable provides

the correct value, and I can bring back the table data with no problem.

 

However, when running the complete code, the query appears not to work. If I echo the

query, and load the php in my browser, an invalid query is displayed lacking the value of the session variable:

 

SELECT * FROM Weiruedits WHERE userid = Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 

 

Therefore there appears to be something about the production of a kml file that stops the session variable from working. The last three lines of code seem to result in no value being returned for $_SESSION[userid].

 

Has anybody come across this problem before, and more importantly does anybody know how to solve it?

 

Thanks for your help

 

Link to comment
Share on other sites

Hi Pikachu2000,

 

Thanks for your post. Yes I have included session_start():

 

session_start();
$userid= etc
$db_name= etc
$server = etc
$user = etc
$password= etc
$db = mysql_connect($server, $user, $password);
if (!$db) 
{ 
die( 'Could not connect: ' . mysql_error()); 
} 
mysql_select_db($db_name, $db); 					
			$userid=$_SESSION[userid];

$query = "SELECT * FROM Weiruedits WHERE userid = " . $userid;

Link to comment
Share on other sites

Hi,

 

Thanks for your help, the issue has now been resolved. A friend sorted it out and sent this explanatory message:

 

'I think you need to pass the session variable in as a parameter

when constructing the overlay http links, as the Javascript is operating in

a separate session.

 

I changed the maps php and the kml php slightly to get it to work.'

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.