Setting a variable in URL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anticore
Forum Newbie
Posts: 21
Joined: Sat Mar 11, 2006 11:37 pm

Setting a variable in URL

Post by anticore »

I'm trying to make a script to call certain rows from a table according to the a catagory called.
so if i would click the link to /list.php?yearcat=9904
the rows pulled would only match the year catagory called

Code: Select all

ini_set('display_errors',true);


if ($yearcat==05up)
{ 
 $cat="05up" ;
} elseif ($yearcat==9904)
{
 $cat="9904";
}elseif ($yearcat==9498)
{
 $cat="9498";
}elseif ($yearcat==8793)
{
 $cat="8793";
}elseif ($yearcat==7986)
{
 $cat="7986";
}


$host="****";
$user="*****";
$pass="l*****";
$db="******";
$tablename="******";


mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
//run query

$query = 'SELECT * FROM $tablename WHERE (yearcat= '$cat')';
if ($r = mysql_query ($query))
{
//print

while ($row = mysql_fetch_array ($r))
{
	print "{$row['name']}";
	
}
else {die('error');
}
mysql_close();

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$_GET['yearcat']

and you should quote 05up at least.
Post Reply