Jump to content

Undefined Index?


Reddevil07utd

Recommended Posts

i am trying to sort out some errors i have on my website but am not really all that clued up with PHP or MySql......

 

currently on this page http://fifaworld360.co.uk/headtohead/team.php i am thrown 3 errors......

 

now it says the errors are on line 11, 12 & 13 which would be this part of the code ....... 

 

	$league = $_REQUEST["league"];
$league_id = get_league_id($league);
$team = rawurldecode($_REQUEST["team"]);

 

below is the full code for this page..... what i need is for someone to tell me if their is something wrong...i got a funny feeling it is something silly but as i said i am not clued up on this at all....the site was built for me and has since been throwing errors when the coder left..... now i just need to sort it so i can re run it again..

 

 

 

if (!isset($_REQUEST["team"])){
$league = $random_league;
$league_id = get_league_id($league);
$team = random_team($league_id);
}else{
$league = $_REQUEST["league"];
$league_id = get_league_id($league);
$team = rawurldecode($_REQUEST["team"]);
}

//echo "<br>team: $team";

$team_information = get_team_information_by_name($team);
$team_id = get_team_id($team_information[1]);
$user_id = get_current_user_id($team_id, $league_id);
$user_name = get_user_name($user_id);

?>
<div class="DivMiddleLeagueTable">
	<table class="layoutTable" width="100%" cellspacing="0" border="0">
		<tbody>
			<tr>
				<td>
					<table class="layoutTable" width="100%" cellspacing="0" cellpadding="0" border="0">
						<tbody>
							<tr>
								<td class="layout" valign="top">
									<div class="layout">
										<div id="leagueTable" class="TeamTable">
											<table class="TeamTable" width="100%" cellspacing="0" border="0">
												<tbody>

													<tr class="header">

														<td colspan="4">Team: <?php echo $team_information[1];?></td>
														<td rowspan="2" align="right" bgcolor='white'><?php echo "<IMG SRC=plaatje.php?plaatje_id=$team_information[0]>";?></td>
													</tr>
													<tr class="header">
														<td colspan="4">League: <?php echo $league;?></td>
													</tr>

													<tr class="rowHeader">
													<td>Ground:</td><td colspan="2"><?php echo $team_information[3];?></td>
													<td>Capacity:</td><td><?php echo $team_information[4];?></td>
													</tr>
													<tr class="rowHeader">
														<td>Manager: </td>
														<td colspan="2"><?php echo $user_name;?></td>
														<td>Partner: </td>
														<td colspan="1"><?php echo get_partner($team_id, $league_id);?></td>
													</tr>

												</tbody>
											</table>
											<br />

									<!-- dit stuk wordt dynamisch gevuld -->
									<?php
		$sql_fixtures = "SELECT f.hometeam_id, f.awayteam_id, f.home_result, f.away_result ".
			"FROM fixtures_result AS f, league AS l ".
			"WHERE f.league_id = '" . mysql_real_escape_string($league_id) . "' AND (f.hometeam_id='" . mysql_real_escape_string($team_id) . "' or f.awayteam_id='" . mysql_real_escape_string($team_id) . "') ".
			"AND f.league_id=l.league_id AND f.week_nr <= l.league_weeknr ".
			"ORDER BY f.week_nr ASC";
		$sql_result = mysql_query($sql_fixtures);
									?>
									<table class="TeamTable" width="100%" cellspacing="0" border="0">
									<tr><td valign="top" width="60%">
										<table width="100%" cellspacing="0" border="0" class="TeamInfo">
											<tr class="header">
												<td colspan="5">Results / Fixtures</td>
											</tr>
										<tbody>
										<?php
										$colourclass = "fixturesLightRow";
										while ($row = mysql_fetch_array($sql_result)){
										?>
											<tr class=<?php echo $colourclass;?>>
												<td class="TeamTD">
													<?php echo get_team_name($row[0]);?>
												</td>
												<td class="TeamTD">
													<?php echo get_team_name($row[1]);?>
												</td>


												<td class="ScoreTD"><?php echo $row[2];?></td>
												<td class="ScoreTD">-</td>
												<td class="ScoreTD"><?php echo $row[3];?></td>
											</tr>
										<?php
										if ($colourclass == "fixturesLightRow"){
											$colourclass = "fixturesDarkRow";
										}elseif ($colourclass == "fixturesDarkRow"){
											$colourclass = "fixturesLightRow";
										}
									}
									?>
									</tbody>
									</table>
									</td><td valign="top" width="35%">
										<?php
										$sql = "SELECT trophy_year, trophy_name FROM `team_history` where team_id=$team_id ORDER BY trophy_year DESC";
										//echo $sql;
										$result = mysql_query($sql);
										?>
										<table width="100%" cellspacing="0" border="0" class="TeamInfo">
											<tr class="header">
												<td colspan="5">Team History</td>
											</tr>


											<tbody>
												<?php
												while ($row = mysql_fetch_array($result)){
												?>
												<tr>
													<td valign="top">
													<?php
														echo $row[0];
													?>
													</td>

													<td><?php echo $row[1];?></td>
												</tr>
												<?php
												}
												?>
											</tbody>
										</table>
									</td>
									</tr>
									<!-- einde vandit stuk wordt dynamisch gevuld -->

											</table>
										</div>
									</div>
								</td>
							</tr>
						</tbody>
					</table>	
				</td>

				<td class="middleRight">
					<img height="1" width="1" alt="" src="images/shim.gif"/>
				</td>
			</tr>
		</tbody>
	</table>
</div>

Link to comment
Share on other sites

are all of the errors "undefined index"? This error normally occurs when an array index is referred to that does not exist.. $_REQUEST["league"] in this case, like you did with $_REQUEST["team"], you must check for the array value being set before assigning the value to a variable.

Link to comment
Share on other sites

kk is this correct???

 

<?php
//smf_members
//member_name
//id_member

if (!isset($_REQUEST["league"]) && isset($_REQUEST['league_id']) && isset($_REQUEST['team'])){
$league = $random_league;
$league_id = get_league_id($league);
$team = random_team($league_id);
}else {
$league = $_REQUEST["league"];
$league_id = $_REQUEST["league_id"];
$team = rawurldecode($_REQUEST["team"]);
}

//echo "<br>team: $team";

$team_information = get_team_information_by_name($team);
$team_id = get_team_id($team_information[1]);
$user_id = get_current_user_id($team_id, $league_id);
$user_name = get_user_name($user_id);

?>

Link to comment
Share on other sites

or is this the way it should be??

 

<?php
//smf_members
//member_name
//id_member

if (!isset($_REQUEST['league']) && isset($_REQUEST['league_id']) && isset($_REQUEST['team'])){
$league = $random_league;
$league_id = get_league_id($league);
$team = random_team($league_id);
}else {(!isset($_REQUEST['league']) && isset($_REQUEST['league_id']) && isset($_REQUEST['team']));
$league = ($_REQUEST['league']);
$league_id = ($_REQUEST['

Link to comment
Share on other sites

if (isset($_REQUEST["league"]) && isset($_REQUEST['league_id']) && isset($_REQUEST['team'])) {
        $league = $_REQUEST["league"];
$league_id = $_REQUEST["league_id"];
$team = rawurldecode($_REQUEST["team"]);
}else {
$league = $random_league;
$league_id = get_league_id($league);
$team = random_team($league_id);
}

 

again, you should be using the proper $_GET or $_POST method.

Link to comment
Share on other sites

if (isset($_REQUEST["league"]) && isset($_REQUEST['league_id']) && isset($_REQUEST['team'])) {
        $league = $_REQUEST["league"];
$league_id = $_REQUEST["league_id"];
$team = rawurldecode($_REQUEST["team"]);
}else {
$league = $random_league;
$league_id = get_league_id($league);
$team = random_team($league_id);
}

 

again, you should be using the proper $_GET or $_POST method.

 

you should copy the above code also and replace the old section with it as that now calls in the correct order hence the undefined index... and changing REQUEST to GET would be a good idea - not essential but highly recommended :D

Link to comment
Share on other sites

ok i have done that and yes it worked but now i am finding that on my fixtures page i have these errors. im not sure as to why???

 

 

i have an undefined variable error

<?php if (($weeknr <> $previousweek) OR ($firstweek)){ ?>

 

and also a undefined index error

 

<?php
									if (($_GET['see']=='own' AND $class=='fixturesDarkRow') OR ($_GET['see']!='own')){
										if ($_GET['see']=='own')$class==''; 

 

i have also tried adding the isset() but to no avail

 

any help would be appreciated

Link to comment
Share on other sites

again: you must check that $_POST or $_GET array values are set by using isset before attempting to use them in your code, if you have attempted to use isset() and the error is still showing, you re doing something wrong and should post that code here. An undefined variable error indicates that you are using a variable that you have not yet given a value.

 

<?php if (($weeknr != $previousweek) || $firstweek){ ?>

Link to comment
Share on other sites

i copied the bottom part but the error remains... where would the best place to look to see why its not set?

 

<?php
isset ($_GET['see']);{
if (($_GET['see']=='own' AND $class=='fixturesDarkRow') OR ($_GET['see']!='own'))
if ($_GET['see']=='own')$class=='';

 

above is how i am  using the isset but still the same error

 

 

 

Link to comment
Share on other sites

i copied the bottom part but the error remains...

 

yes, because you are attempting to use a variable that has not been declared previously. If you cannot fix this, we would need to see the relevant code above this line where these variables are declared.

 

<?php
isset ($_GET['see']);{
if (($_GET['see']=='own' AND $class=='fixturesDarkRow') OR ($_GET['see']!='own'))
if ($_GET['see']=='own')$class=='';

 

above is how i am  using the isset but still the same error

 

 

i hope that isn't a copy paste, if so, syntax is wrong.

 

if(isset($_GET['see']))
{
//do whatever with $_GET['see']
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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