Creating Dynamic Meta Tags With Php, help!

Need some help and first let me say I am no programmer and too old to learn. I can edit some Php but that is as far as it goes. I want to create dynamic meta tags for my site but having a few issues.

I have a header.php that pulls the normal meta tags but I need to have dynamic on all other pages. So this is what I did and I know some may laugh as it could be done easier probably.

I created header2.php and included

$imageid = $_GET['image'];
  <meta name="keywords" content="<?=$resource_tags?>"/>
  <meta name="description" content="<?=$description;?>"/>
  <meta name="revisit" content="<?=$meta_revisit?>"/>
  <meta http-equiv="Content-Type" content="text/htm;">

The functions has

function getimage($image)
	global $link;
	$qry = sprintf("select * from turnkeys_images where id=%d",$image);
	$res = mysql_query($qry,$link);
	$info = mysql_fetch_object($res);
	return $info;

One page I am testing this on obviously includes the header2.php file

The meta tags show up and the title shows but the problem is it is pulling the info from the first id in the images database. It does not pull up the proper meta tags and title because no id is specified I would assume.

So my question is how do I get this to pull the proper id ? If my page shows image id = 40 then that is the meta tags it should be using.

Opps I forgot I have a config2.php

include "";

$metasettings = @mysql_fetch_assoc(@mysql_query("SELECT * FROM turnkeys_images", $link));

$title = $metasettings['title'];
$description = $metasettings['description'];
$resource_tags = $metasettings['resource_tags'];