someone will type in what year they left
Where do they do this?
This is a string
$query = "SELECT yr_left, city_origin, country_origin, yr_arrival, city_arrival, state_arrival, filename FROM story WHERE pamapproved = 'Y' and yr_left = $yr_left ORDER by yr_left";
This will not execute because you don't encapsulate the string $yr_left in quotes in the query (like you did with pamapproved). So the query you get looks like this:
SELECT yr_left, city_origin, country_origin, yr_arrival, city_arrival, state_arrival, filename
FROM story
WHERE pamapproved = 'Y'
AND yr_left = Year Left
ORDER by yr_left
Note: Broken up for aesthetics
and so when mySQL looks at the query, it will see:
WHERE pamapproved='Y' AND yr_left='Year' LEFT ORDER BY
so it should interpret the "Left" as a command, and if it does, it's wanting a specific syntax with it (Join for instance) and it's not seeing it. Thus, you get a mySQL error. And your query doesn't work.
Now, since in your code you thought "What if the query fails? I'll need to let the user know!!" you put in some error checking:
if (!$result)
{
echo 'Query on Connection failed!';
// exit
}
Which says that if there is no result (or a proper result resource ID returned by the query) to print on screen "Query on Connection failed!". Not very helpful. Obviously, this is not very informative; however to the end user it's fine. But for now, we need more info. So perhaps you should say something like:
if(!$result)
{
die('Query on mySQL database failed. The error returned was:<br>'.mysql_error());
}
That will give you information about the query you ran and what mySQL is having trouble with.
Now, before you do that, I suggest modifying your query from:
$query = "SELECT yr_left, city_origin, country_origin, yr_arrival, city_arrival, state_arrival, filename FROM story WHERE pamapproved = 'Y' and yr_left = $yr_left ORDER by yr_left";
to
$query = "SELECT yr_left, city_origin, country_origin, yr_arrival, city_arrival, state_arrival, filename FROM story WHERE pamapproved = 'Y' and yr_left = '$yr_left' ORDER by yr_left";
But that still doesn't take into account the type of field (number or text) yr_left is. If it's a numerical field (INT, LONG INT, YEAR) then mySQL won't return any rows from your query if you pass it a string (like "Year Left"). Understand?