Lately I have been learning how to use 'sessions' (with some degree of success) for transferring parameters between pages. I have come across a new error report that is so weird that I would not be able to envision how I could do a Google search to find what is happening. I am so close ----- and (so far) so far away from being able to display images in a pop-up window.

First, some background to get you going.
The website is at

On the left side menu, clicking on 'Woody Species' will bring up a huge list of over 15,000 botanical wood names. Each is linked to bring up (dynamically) a data sheet on
the specific wood chosen.

Some woods show a picture (scan) of the wood, some do not have one. Just below that picture area (scan present or absent) are three buttons to bring up three pop-up windows:
Photomicrographs More Photos U.V. Fluoresence
Each of the new windows are planned to show the content of the titles. To get the appropriate image to show for the currently chosen wood requires supporting code to sort through stored photos and images and to display it. I chose to do the development first on the 'U.V. Fluorescence' pop-up. (Incidentally, I have found that as much as 10% - 15% of the 3,000 woods in my collection will actually glow under ultraviolet light and I found that I can photograph this).

Once I get any one of these windows working OK, it will become much easier to get all three pop-ups to display their images.

Each of these pop-up pages start with a session start statement so it can find what the currently chosen botanical name is. The page starts with a title of:
Woody Species (botanical name of the wood)

An example would be Woody Species Acacia aneura

When you pick a different wood, the page successfully changes the title to reflect the name of the newly chosen wood. That shows that the session is at least working properly.

The Problem
I get no errors on connecting to the database. Even the SELECT statement is read OK with no errors. When I bypass the path and file name coming from the database by hard coding it, the picture shows fine(!). However -- when I instead try to go the next step with a mysql_query statement, I get a really weird and fatal error (no window forms) reporting of:

"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 'aneura' at line 3".

However, all there is at line 3 is:

No mention of 'aneura' is made at all. Furthermore, all species names are made from two words (not one). The current correct species name actually is
Acacia aneura, so the error has to be related to the hidden value in the session.
I have NO IDEA how to fix this or what the system actually is complaining about.

I will leave the page hard wired for now so anyone can see the objective of how I
want the page to show. I will also include the source code below for the page.

What is happening? Has anyone come across an error like this? I doubt I would be able to know what to search for on the Net for this one.

Even MORE important ----- How can I get this page to display the right photo for a pre-chosen botanical name? If you need more information I am glad to send it.
(recall that if I get this working, two other pop-ups will also become easier to
finish off).

(Once again, fingers and toes crossed!)

Bill Mudry
Mississauga, Ontario



//ECHO "Session variable for species name is - {$_SESSION['species_name']}";  //Debug statement

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<title>TAXA: Ultraviolet Wood Fluorescence</title>


<body bgcolor='ivory'>


# ////////////////////////////////////////////////////////////////////////////////////
#				            CONNECT TO DATABASE
# ////////////////////////////////////////////////////////////////////////////////////

include ("connecttotaxa.php");
$connection = mysql_connect($hostname, $username, $password) 
	or die("Unable to connect to database server");

$db = mysql_select_db($dbname, $connection)
	or die("Unable to connect to database");



	Echo "<div align = 'center'>";

	Echo "<H2 align=\'center\'>Ultraviolet Fluorescence Photo of 

	echo "<br />";

	$uvquery = "SELECT * 
	FROM uvphotos
	WHERE species_name = {$_SESSION["speciesname"]}";

	//$resultuv = mysql_query($uvquery) or die(mysql_error());
	//mysql_query($uvquery) or die(mysql_error());

	ECHO "\$uvfilename on line 62 is - $uvfilename<br /><br />";

	$uvfilename = "uva/acacia_anura-mulgaUV01-800.JPG";
	$uvpath = "./uv/$uvfilename";

	ECHO "<img src='$uvpath'><br />";
	ECHO "<HR>";

  Echo "<br />END OF PICTURE AREA<br /><br />";

Echo "</div>";


<h4 align="center">Webmaster: This function is still Under Construction</h4>

<table align='center' cellpadding='10', Cellspacing='20' border =1>
	<td valign='top'>
		<form name='NewWin'>
			<p><A href="javascript: self.close ()">Close this Window</A></p>



Recommended Answers

All 3 Replies


You have misunderstood the error. It is referring to Line 3 in a MySQL Query.

If this is what is causing it:

$uvquery = "SELECT *
FROM uvphotos
WHERE species_name = {$_SESSION["speciesname"]}";

You should try:

$uvquery = "SELECT * FROM `uvphotos` WHERE `species_name` = '{$_SESSION["speciesname"]}'";

Hope This Helps
Kieran ;)

I don't think it's a session error, it is a problem with the query itself.
"No mention of 'aneura' is made at all. Furthermore, all species names are made from two words (not one). The current correct species name actually is
Acacia aneura, so the error has to be related to the hidden value in the session."
step 1, echo your query out before you send it to the database.
It is not the query you think it is.

$uvquery = "SELECT * 
    FROM uvphotos
    WHERE species_name = {$_SESSION["speciesname"]}";

you are attempting to set the 'specites_name' variable with {$_SESSION["speciesname"]} which is correct, what you need to do is (since you are using quote marks on the outside) use ticks to make it appear as a string to the database. so sql = "blah blah WHERE species_name = '{$_SESSION["speciesname"]}'";

I'm not sure it that will 100% solve your problem but you should be closer.

Kieran, you and Sacha were right. Your code was especially useful since the
error disappeared using it. Thanks. This is the first time that I cane across
line numbering not always being referred to from the very top of the code page.

Further down the code I have some other problems but for now, I want to struggle
toward a solution a bit more by myself first before presenting it.

Bill Mudry
Mississauga, ON

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.