Jump to content

get method


clarky08

Recommended Posts

Hi I am just starting with PHP and I was wondering if someone would be kind enough to help me. I want to use the get method to send a variable to the next page. I am making a website for football clubs and i have a database witht the following fields:

 

ClubID

ClubName

ClubManger

 

On the first page there is a list of clubs names. When you click on the clubs name I want it to bring you to the profile page of that club. So what i want is for when someone clicks on Arsenal, for example, their id number is sent onto the profile.php page and I can get the ClubName and ClubManager fields out of the database using the ClubID.

 

Thanks in advance,

Colm

Link to comment
https://forums.phpfreaks.com/topic/99175-get-method/
Share on other sites

On index.php, something like ...

<?php
$sql = "SELECT * FROM `table`";
$result = mysql_query($sql) OR DIE (mysql_error());
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_array($result))
{
	$clubid = $row['id'];
	$clubname = $row['name'];
	$clubmanager = $row['manager'];
	echo "<div>";
	echo "<a href=\"page.php?cid={$clubid}&cn={$clubname}&cm={clubmanager}\">";
	echo "{$clubname}";
	echo "</a>";
	echo "</div>";
}
}
?>

 

Then on page.php, something like ...

<?php
function myEscape($string)
{
// db connection goes here
$var = get_magic_quotes_gpc() ? stripslashes($string) : $string;
return mysql_real_escape_string($var);
}

$cid = myEscape($_GET['cid']);
$cn = myEscape($_GET['cn']);
$cm = myEscape($_GET['cm']);
$sql = "SELECT * FROM `table` WHERE `id`='$cid' AND `name`='$cn' AND `manager`='$cm'";
$result = mysql_query($sql) OR DIE (mysql_error());
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_array($result))
{
	// get and show whatever data you want
}
}
else
{
echo "Houston? We have a problem.";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/99175-get-method/#findComment-507408
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.