reinmedia Posted November 27, 2007 Share Posted November 27, 2007 This page has been working for about a year. A couple weeks ago it just stopped loading the db. I create the db or php, I had someone else create it for me. I am a novice at best when it comes to mysql and php, very basic skills. I have dissected the php code and when I remove the $QUERY_STRING and replace it with lastname for instance, the db will function. I'm not sure if this is the problem, but it's all I can find. Any help would be appreciated. http://www.southbayvbc.com/teams.php?18-1 (re-directs back to index when db doesn't work) <?php //global functions (age, birthday, grade) function getAge($dob){ $ageparts = explode("-",$dob); $age = date(Y) - $ageparts[0]; if (date(m) >= $ageparts[1]){ if(date(d) >= $ageparts[2]){ return $age; }else{ return $age-1; } }else{ return $age-1; } } function niceBirthday($dob){ $dobparts = explode("-",$dob); if($dobparts[1] == "01"){$nicemonth="January";} if($dobparts[1] == "02"){$nicemonth="February";} if($dobparts[1] == "03"){$nicemonth="March";} if($dobparts[1] == "04"){$nicemonth="April";} if($dobparts[1] == "05"){$nicemonth="May";} if($dobparts[1] == "06"){$nicemonth="June";} if($dobparts[1] == "07"){$nicemonth="July";} if($dobparts[1] == "08"){$nicemonth="August";} if($dobparts[1] == "09"){$nicemonth="September";} if($dobparts[1] == "10"){$nicemonth="October";} if($dobparts[1] == "11"){$nicemonth="November";} if($dobparts[1] == "12"){$nicemonth="December";} return($nicemonth." ".$dobparts[2].", ".$dobparts[0]); } function nicegrade($schoolgrade){ if ($schoolgrade == "12"){$schoolgrade = "Senior";} if ($schoolgrade == "11"){$schoolgrade = "Junior";} if ($schoolgrade == "10"){$schoolgrade = "Sophomore";} if ($schoolgrade == "9") {$schoolgrade = "Freshman";} return $schoolgrade; } function getPreviousTeam($team) { if ($team == "18-1") return "17-1"; if ($team == "17-1") return "16-1"; if ($team == "16-1") return "16-Gold"; if ($team == "16-Gold") return "16-Blue"; if ($team == "16-Blue") return "15-1"; if ($team == "15-1") return "15-Gold"; if ($team == "15-Gold") return "14-1"; if ($team == "14-1") return "14-Gold"; if ($team == "14-Gold") return "13-1"; if ($team == "13-1") return "12-1"; if ($team == "12-1") return "12-Gold"; if ($team == "12-Gold") return "12-Blue"; if ($team == "12-Blue") return "18-1"; // error case: return current team return $team; } function getNextTeam($team) { if ($team == "18-1") return "12-Blue"; if ($team == "17-1") return "18-1"; if ($team == "16-1") return "17-1"; if ($team == "16-Gold") return "16-1"; if ($team == "16-Blue") return "16-Gold"; if ($team == "15-1") return "16-Blue"; if ($team == "15-Gold") return "15-1"; if ($team == "14-1") return "15-Gold"; if ($team == "14-Gold") return "14-1"; if ($team == "13-1") return "14-Gold"; if ($team == "12-1") return "13-1"; if ($team == "12-Gold") return "12-1"; if ($team == "12-Blue") return "12-Gold"; // error case: return current team return $team; } function coachPage($team) { if ($team == "18-1") return "staff.html"; if ($team == "17-1") return "staff.html"; if ($team == "16-1") return "16.html"; if ($team == "16-Gold") return "16.html"; if ($team == "16-Blue") return "16.html"; if ($team == "15-1") return "16.html"; if ($team == "15-Gold") return "16.html"; if ($team == "14-1") return "14.html"; if ($team == "14-Gold") return "14.html"; if ($team == "13-1") return "14.html"; if ($team == "12-1") return "12.html"; if ($team == "12-Gold") return "12.html"; if ($team == "12-Blue") return "12.html"; // error case: return current team return $team; } ?> ?php if(!$QUERY_STRING){echo("<script language='Javascript'>window.location.href='index.php'</script>");} // Connect to the database server $dbcnx = @mysql_connect("localhost", "southbay_lindsey", "makana"); if (!$dbcnx) { echo( "<p>Unable to connect to the " . "database server at this time.</p>" ); exit(); } // Select the southbay_webdata database if (! @mysql_select_db("southbay_webdata") ) { echo( "<p>Unable to locate the southbay_webdata " . "database at this time.</p>" ); exit(); } //Query Players $result = @mysql_query("SELECT * FROM players WHERE team='$QUERY_STRING' ORDER BY lastname"); //check for garbage query_string if (!mysql_num_rows($result)){echo("<script language='Javascript'>window.location.href='index.php'</script>");} ?> <script language="javascript"> <?php $n=0; while( $row = mysql_fetch_array($result) ){ if ( file_exists ("images/players/".strtolower($row[lastname])."_".strtolower($row[firstname]).".jpg")) { $playerphoto = "images/players/".strtolower($row[lastname])."_".strtolower($row[firstname]).".jpg"; } else { $playerphoto = "images/players/playerna.jpg"; } echo("imgload".$n." = new Image;\nimgload".$n.".src = '".$playerphoto."';\n"); $n++; } mysql_data_seek($result,0); ?> <?php //Player Query executed in <head> for redirections purposes //Scrub Characters $search = array("'","\"",","); $replace = array("-","",""); //Query Coaches $coach_result = @mysql_query("SELECT * FROM coaches WHERE team='$QUERY_STRING' ORDER BY position"); if (!$coach_result) { echo("<p>Error performing query: " . mysql_error() . "</p>"); exit(); } //Get coaches email now, do the other coach stuff later while ($coach_check = mysql_fetch_array($coach_result)){ if ($coach_check[position] == "Coach") { $coach_email = $coach_check[email]; } } //reset pointer for later use of mysql_fetch_array() if(mysql_num_rows($coach_result)) { mysql_data_seek ($coach_result ,0); } //Check for IE ( uses javascript function playersuffleIE() ) if(strstr($HTTP_USER_AGENT,"MSIE")) { while ( $row = str_replace($search,$replace,mysql_fetch_array($result)) ) { if ( file_exists ("images/players/".strtolower($row[lastname])."_".strtolower($row[firstname]).".jpg")) { $playerphoto = "images/players/".strtolower($row[lastname])."_".strtolower($row[firstname]).".jpg"; } else { $playerphoto = "images/players/playerna.jpg"; } echo("<tr bgcolor='#ffffff'><td width='113' height='20' align='center'>"); // Check for young players if( preg_match("(^1[2-4])",$row[team]) ) { echo("\n<a onclick='youngplayershuffle(\"".$row[firstname]."\",\"".$row[lastname]."\",\"".niceBirthday($row[birthdate])."\",\"".getAge($row[birthdate])."\",\"".$row[position]."\",\"".nicegrade($row[grade])."\",\"".$row[email]."\",\"".$row[committed]."\",\"".$row[height]."\",\"".$row[number]."\",\"".$row[highschool]."\",\"".$row[gpa]."\",\"".$row[sat]."\",\"".$row[reach]."\",\"".$row[block]."\",\"".$row[approach]."\",\"".$playerphoto."\",\"".$coach_email."\")' href='javascript:;'>" . $row[firstname] . " ". $row[lastname] . "</a></td>\n"); } else { echo("\n<a onclick='playershuffle(\"".$row[firstname]."\",\"".$row[lastname]."\",\"".niceBirthday($row[birthdate])."\",\"".getAge($row[birthdate])."\",\"".$row[position]."\",\"".nicegrade($row[grade])."\",\"".$row[email]."\",\"".$row[committed]."\",\"".$row[height]."\",\"".$row[number]."\",\"".$row[highschool]."\",\"".$row[gpa]."\",\"".$row[sat]."\",\"".$row[reach]."\",\"".$row[block]."\",\"".$row[approach]."\",\"".$playerphoto."\",\"".$coach_email."\")' href='javascript:;'>" . $row[firstname] . " ". $row[lastname] . "</a></td>\n"); } echo("<td width='20' height='20'><div align='center'>" . $row[number] . "</div></td>\n"); echo("<td width='69' height='20'><div align='center'>" . $row[position] . "</div></td>\n"); echo("<td width='99' height='20'><div align='center'>" . $row[highschool] . "</div></td>\n"); echo("<td width='36' height='20'><div align='center'>" . $row[year] . "</div></td>\n</tr>"); } // All other browsers ( uses javascript function playersuffle() ) } else { while ( $row = str_replace($search,$replace,mysql_fetch_array($result)) ) { if ( file_exists ("images/players/".strtolower(str_replace(" ","_",$row[lastname]))."_".strtolower(str_replace(" ","_",$row[firstname])).".jpg")) { $playerphoto = "images/players/".strtolower(str_replace(" ","_",$row[lastname]))."_".strtolower(str_replace(" ","_",$row[firstname])).".jpg"; } else { $playerphoto = "images/players/playerna.jpg"; } echo("<tr bgcolor='#ffffff'><td width='113' height='20' align='center'>"); // Check for young players if( preg_match("(^1[2-4])",$row[team]) ){ echo("\n<a onclick='youngplayershuffle(\"".$row[firstname]."\",\"".$row[lastname]."\",\"".niceBirthday($row[birthdate])."\",\"".getAge($row[birthdate])."\",\"".$row[position]."\",\"".nicegrade($row[grade])."\",\"".$row[email]."\",\"".$row[committed]."\",\"".$row[height]."\",\"".$row[number]."\",\"".$row[highschool]."\",\"".$row[gpa]."\",\"".$row[sat]."\",\"".$row[reach]."\",\"".$row[block]."\",\"".$row[approach]."\",\"".$playerphoto."\",\"".$coach_email."\")' href='javascript:;'>" . $row[firstname] . " ". $row[lastname] . "</a></td>\n"); } else { echo("\n<a onclick='playershuffle(\"".$row[firstname]."\",\"".$row[lastname]."\",\"".niceBirthday($row[birthdate])."\",\"".getAge($row[birthdate])."\",\"".$row[position]."\",\"".nicegrade($row[grade])."\",\"".$row[email]."\",\"".$row[committed]."\",\"".$row[height]."\",\"".$row[number]."\",\"".$row[highschool]."\",\"".$row[gpa]."\",\"".$row[sat]."\",\"".$row[reach]."\",\"".$row[block]."\",\"".$row[approach]."\",\"".$playerphoto."\",\"".$coach_email."\")' href='javascript:;'>" . $row[firstname] . " ". $row[lastname] . "</a></td>\n"); } echo("<td width='20' height='20'><div align='center'>" . $row[number] . "</div></td>\n"); echo("<td width='69' height='20'><div align='center'>" . $row[position] . "</div></td>\n"); echo("<td width='99' height='20'><div align='center'>" . $row[highschool] . "</div></td>\n"); echo("<td width='36' height='20'><div align='center'>" . $row[year] . "</div></td>\n</tr>"); } } //Coaches rows $csearch = array("'","\"","\n","\r","(",")"); $creplace = array("","","<br>","<br>","",""); while ( $row = str_replace($csearch,$creplace,mysql_fetch_array($coach_result)) ) { if($row[position]=='Assistant'){ echo("<tr bgcolor='#ffffff'>\n<td width='113' height='20'><div align='center'>\n<b>"); echo("<a href='" . coachPage($QUERY_STRING) . "#" . $row[firstname] . "'>" . $row[firstname] . " " . $row[lastname] . "</a></b></div>\n</td>\n"); echo("<td height='20' colspan='4' class='team-footer'><b>Assistant Coach</b></td>\n</tr>\n"); } else { echo("<tr bgcolor='#ffffff' id='headeryellow'>\n<td width='113' height='20'><div align='center'>\n<b>"); echo("<a href='" . coachPage($QUERY_STRING) . "#" . $row[firstname] . "'>" . $row[firstname] . " " . $row[lastname] . "</a></b></div>\n</td>\n"); echo("<td height='20' colspan='4' class='team-footer'><b>Coach</b></td>\n</tr>\n"); } } Quote Link to comment https://forums.phpfreaks.com/topic/79016-db-stopped-loading/ Share on other sites More sharing options...
todding01 Posted November 27, 2007 Share Posted November 27, 2007 Usually a piece of code won't just stop connecting. There has been some change. Maybe an upgrade on the SQL server or the PHP version. What database and php versions are currently on the server? Quote Link to comment https://forums.phpfreaks.com/topic/79016-db-stopped-loading/#findComment-399865 Share on other sites More sharing options...
todding01 Posted November 27, 2007 Share Posted November 27, 2007 ?> ?php if(!$QUERY_STRING){echo("<script language='Javascript'>window.location.href='index.php'</script>");} You are missing the < before the php code starts again... It should be: ?> <?php if(!$QUERY_STRING){echo("<script language='Javascript'>window.location.href='index.php'</script>");} Quote Link to comment https://forums.phpfreaks.com/topic/79016-db-stopped-loading/#findComment-399868 Share on other sites More sharing options...
trq Posted November 27, 2007 Share Posted November 27, 2007 On top of that.... You've really posted too much code to be able to debug it all, but the $QUERY_STRING variable has long been depricated in favor of $_SERVER['QUERY_STRING']. Its probably about time you had this site rebuilt or at the very least reworked to comply with the changes that have happend to php over the last few years. Quote Link to comment https://forums.phpfreaks.com/topic/79016-db-stopped-loading/#findComment-399872 Share on other sites More sharing options...
reinmedia Posted November 27, 2007 Author Share Posted November 27, 2007 sloppy copy and pasting by me. The tag is closed properly. Looks like version 4.1.22 Quote Link to comment https://forums.phpfreaks.com/topic/79016-db-stopped-loading/#findComment-399876 Share on other sites More sharing options...
reinmedia Posted November 27, 2007 Author Share Posted November 27, 2007 On top of that.... You've really posted too much code to be able to debug it all, but the $QUERY_STRING variable has long been depricated in favor of $_SERVER['QUERY_STRING']. Its probably about time you had this site rebuilt or at the very least reworked to comply with the changes that have happend to php over the last few years. The original code was written over three years ago then updated last year. I guess this is the most important piece of code if I could get it to work: //Query Players $result = @mysql_query("SELECT * FROM players WHERE team='$QUERY_STRING' ORDER BY lastname"); Quote Link to comment https://forums.phpfreaks.com/topic/79016-db-stopped-loading/#findComment-399878 Share on other sites More sharing options...
trq Posted November 27, 2007 Share Posted November 27, 2007 I'm sorry to say but it looks like pretty poor code to begin with. You could try.... $result = mysql_query("SELECT * FROM players WHERE team='{$_SERVER['QUERY_STRING']}' ORDER BY lastname"); but I'm sure there will be other issues. Quote Link to comment https://forums.phpfreaks.com/topic/79016-db-stopped-loading/#findComment-399883 Share on other sites More sharing options...
reinmedia Posted November 27, 2007 Author Share Posted November 27, 2007 Well...that worked. But you're right about the other issues. Looks like it's time to bite the bullet and get it re-worked. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/79016-db-stopped-loading/#findComment-399893 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.