Reddevil07utd Posted January 30, 2012 Share Posted January 30, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/256043-undefined-index/ Share on other sites More sharing options...
AyKay47 Posted January 30, 2012 Share Posted January 30, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/256043-undefined-index/#findComment-1312575 Share on other sites More sharing options...
PaulRyan Posted January 30, 2012 Share Posted January 30, 2012 You really shouldn't use $_REQUEST, here is why http://devlog.info/2010/02/04/why-php-request-array-is-dangerous/ Try using $_GET or $_POST, for your incoming data. Regards, PaulRyan. Quote Link to comment https://forums.phpfreaks.com/topic/256043-undefined-index/#findComment-1312589 Share on other sites More sharing options...
Reddevil07utd Posted January 30, 2012 Author Share Posted January 30, 2012 so far i have only found these errors on this page i have mentioned....however i leagues have been creates and so have teams which is why im not sure why these errors show...... :'( Quote Link to comment https://forums.phpfreaks.com/topic/256043-undefined-index/#findComment-1312592 Share on other sites More sharing options...
AyKay47 Posted January 30, 2012 Share Posted January 30, 2012 where are the $_REQUEST values coming from? Quote Link to comment https://forums.phpfreaks.com/topic/256043-undefined-index/#findComment-1312593 Share on other sites More sharing options...
spiderwell Posted January 30, 2012 Share Posted January 30, 2012 use the isset() on league in the else statement, because currently if you Dont have team , it automatically assumes league exists in the request object. personally i would switch to post or get too Quote Link to comment https://forums.phpfreaks.com/topic/256043-undefined-index/#findComment-1312595 Share on other sites More sharing options...
Reddevil07utd Posted January 30, 2012 Author Share Posted January 30, 2012 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/256043-undefined-index/#findComment-1312604 Share on other sites More sharing options...
Reddevil07utd Posted January 30, 2012 Author Share Posted January 30, 2012 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[' Quote Link to comment https://forums.phpfreaks.com/topic/256043-undefined-index/#findComment-1312609 Share on other sites More sharing options...
AyKay47 Posted January 30, 2012 Share Posted January 30, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/256043-undefined-index/#findComment-1312627 Share on other sites More sharing options...
Reddevil07utd Posted January 30, 2012 Author Share Posted January 30, 2012 so do i have to change all the $_REQUESTS to $_GET ?? Quote Link to comment https://forums.phpfreaks.com/topic/256043-undefined-index/#findComment-1312634 Share on other sites More sharing options...
AyKay47 Posted January 30, 2012 Share Posted January 30, 2012 so do i have to change all the $_REQUESTS to $_GET ?? don't have to technically, but you most certainly should. Quote Link to comment https://forums.phpfreaks.com/topic/256043-undefined-index/#findComment-1312637 Share on other sites More sharing options...
angelclawdust Posted January 30, 2012 Share Posted January 30, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/256043-undefined-index/#findComment-1312651 Share on other sites More sharing options...
Reddevil07utd Posted January 30, 2012 Author Share Posted January 30, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/256043-undefined-index/#findComment-1312716 Share on other sites More sharing options...
AyKay47 Posted January 30, 2012 Share Posted January 30, 2012 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){ ?> Quote Link to comment https://forums.phpfreaks.com/topic/256043-undefined-index/#findComment-1312717 Share on other sites More sharing options...
Reddevil07utd Posted January 30, 2012 Author Share Posted January 30, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/256043-undefined-index/#findComment-1312719 Share on other sites More sharing options...
AyKay47 Posted January 30, 2012 Share Posted January 30, 2012 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'] } Quote Link to comment https://forums.phpfreaks.com/topic/256043-undefined-index/#findComment-1312723 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.