Query trouble

I am trying to create a table join query dependent on what the user clicks on the previous page.

This is the variable that is passed over –

echo '<td><a href="team-selection.php?team=' . rawurlencode($row['Team']). '" class="emaillink">Team Selection</a>' . '</td>';

It comes over correctly attached to the url string

Then this is the page that it should work on but I get the following error

Notice: Undefined variable: Team in C:\Program Files\EasyPHP-5.3.6.0\www\DBGS\ est\ eam-selection.php on line 19

Notice: Undefined variable: Team in C:\Program Files\EasyPHP-5.3.6.0\www\DBGS\ est\ eam-selection.php on line 19
Query Failed: Please Contact Us

Code for the page is below

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>


<?php include("database.php");?>

<?php

if (isset($_GET['Team']))

{$Team = $_GET['Team'];}

$query = ("SELECT * FROM Results, Teams WHERE Teams.Team = '$Team' AND Results.Home Team = '$Team';");


$result = mysql_query($query) or die("Query Failed: Please Contact Us");

$num_rows = mysql_num_rows($result);

if ($num_rows == 1)

{echo "Currently there is $num_rows result in the sales contact table";}

else

{echo "Currently there are $num_rows results in the sales contact table";}



echo '<table class="sortable">';

echo '<tr><th>date</th><th>Home Team</th><th>Away Team</th><th>FT Home Goals</th><th>FT Away Goals</th></tr>';



$color1 = "#ffffff"; 

$color2 = "#ebeced"; 

$row_count = 0;



while($row = mysql_fetch_assoc($result))

{

$row_color = ($row_count % 2) ? $color1 : $color2;

echo '<tr bgcolor="' . $row_color . '">';

echo '<td>' . $row['Date'] . '</td>'; 

echo '<td>' . $row['Home Team'] . '</td>';

echo '<td>' . $row['Away Team'] . '</td>';

echo '<td>' . $row['FT Home Goals'] . '</td>';

echo '<td>' . $row['FT Away Goals'] . '</td>';

echo '</tr>';

$row_count ++;

}

echo '</table>';

?>


</body>
</html>

Thank You for any help

problem in your query ,create alias name for table and check the query is run in your mysql ,then apply to your code.

If you are using php 5.3.x, this can be annoying. You can turn this off in your php.ini with the following settings.

error_reporting = E_ALL & ~E_NOTICE

Then restart apache.

Change:


$result = mysql_query($query) or die("Query Failed: Please Contact Us");

To:


$result = mysql_query($query) or die("Query Failed: " . mysql_error());

It will tell you why it failed, then inspect $query to see if it contains what you expect.

there’s your error right there

table column names should not contain spaces – if they do, you have to escape the name properly with backticks

I have been editing the form and worked on the SQL in MYSQL to ensure the query works correctly which it does now.

However I have got a really annoying error now.

I am passing the value name over by the url below

echo '<td><a href="team-selection.php?team=' . rawurlencode($row['Name']). '">Team Selection</a>' . '</td>'; 

But when I get to teh actual page I have tried the bleow but get the following error message

if (isset($_GET['name']))
{$name = $_GET['name'];}

echo $name;
exit();

Notice: Undefined variable: name in C:\Program Files\EasyPHP-5.3.6.0\www\DBGS\ est\ eam-selection.php on line 18

Full pages below thanks for nay help

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>


<?php include("database.php");?>

<?php

$query = ("SELECT * FROM company where year = '2010';");



$result = mysql_query($query) or die("Query Failed: Please Contact Us");

$num_rows = mysql_num_rows($result);

if ($num_rows == 1)

{echo "Currently there is $num_rows result in the sales contact table";}

else

{echo "Currently there are $num_rows results in the sales contact table";}



echo '<table class="sortable">';

echo '<tr><th>Year</th><th>Company</th></tr>';



$color1 = "#ffffff"; 

$color2 = "#ebeced"; 

$row_count = 0;



while($row = mysql_fetch_assoc($result))

{

$row_color = ($row_count % 2) ? $color1 : $color2;

echo '<tr bgcolor="' . $row_color . '">';

echo '<td>' . $row['Year'] . '</td>'; 

echo '<td>' . $row['Name'] . '</td>';

echo '<td><a href="team-selection.php?team=' . rawurlencode($row['Name']). '">Team Selection</a>' . '</td>'; 

echo '</tr>';

$row_count ++;

}

echo '</table>';

?>


</body>
</html>

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;


&lt;?php include("database.php");?&gt;

&lt;?php

if (isset($_GET['name']))
{$name = $_GET['name'];}

echo $name;
exit();

$query = ("SELECT * FROM `all-data` JOIN `company` ON `HT` = '$name' AND `name` = '$name' OR `AT` = '$name' AND `name` = '$name' ORDER BY date ASC ;");


$result = mysql_query($query) or die("Query Failed: " . mysql_error());

$num_rows = mysql_num_rows($result);

if ($num_rows == 1)

{echo "Currently there is $num_rows result in the sales contact table";}

else

{echo "Currently there are $num_rows results in the sales contact table";}



echo '&lt;table class="sortable"&gt;';

echo '&lt;tr&gt;&lt;th&gt;date&lt;/th&gt;&lt;th&gt;HT&lt;/th&gt;&lt;th&gt;AT&lt;/th&gt;&lt;th&gt;FTHG&lt;/th&gt;&lt;th&gt;FTAG&lt;/th&gt;&lt;/tr&gt;';



$color1 = "#ffffff"; 

$color2 = "#ebeced"; 

$row_count = 0;



while($row = mysql_fetch_assoc($result))

{

$row_color = ($row_count % 2) ? $color1 : $color2;

echo '&lt;tr bgcolor="' . $row_color . '"&gt;';

echo '&lt;td&gt;' . $row['Date'] . '&lt;/td&gt;'; 

echo '&lt;td&gt;' . $row['HT'] . '&lt;/td&gt;';

echo '&lt;td&gt;' . $row['AT'] . '&lt;/td&gt;';

echo '&lt;td&gt;' . $row['FTHG'] . '&lt;/td&gt;';

echo '&lt;td&gt;' . $row['ATHG'] . '&lt;/td&gt;';

echo '&lt;/tr&gt;';

$row_count ++;

}

echo '&lt;/table&gt;';

?&gt;


&lt;/body&gt;
&lt;/html&gt;

The query parameter is team but you are trying to get name , how is it possible?
try with $_Get[‘team’]

sorry that error is fixed but still getting the error

Notice: Undefined variable: name in C:\Program Files\EasyPHP-5.3.6.0\www\DBGS\ est\ eam-selection.php on line 18

fixed thanks for all the hlep