PHP right syntax to use near 'ORDER BY"

This is my first post here and I am still learning PHP, I have gone through and fixed all the bugs that I could find, T-strings and what not but I get the following error “You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘ORDER BY Players.LastName’ at line 12” Line 12 on my Notepad ++ is a blank line between the and <?php I have gone through with my limited knowledge and tried to find out what the problem could be but without more of an error to help me I can’t seem to get any further. Thanks For taking a look at this. I think I formatted this correctly.

[code]

} td img { vertical-align: top; } CNGHL Database [/code]

[php]<?php
// Connects to your Database
mysql_connect("", “”, “”) or die(mysql_error());
mysql_select_db("") or die(mysql_error());

//Get PlayerID from URL
$iPlayerID = $_GET[“PlayerID”];
$iNationID = $_GET[“NationID”];

$oPlayerInfo = mysql_query("
SELECT Players.PlayerID, Players.FirstName, Players.LastName, Players.Position, Players.Height, Players.Weight, Players.DOB, CNGHLTeams.CNGHLRights, NHLTeams.Team, Players.CNDraftYR, DraftTeam.DraftID, Players.CNDraftPOS, Countries.Nation, Players.NationID, DraftTeam.DrTeam
FROM Players
Left JOIN CNGHLTeams
ON Players.CNGHLID=CNGHLTeams.CNGHLID
Left JOIN NHLTeams
ON Players.TeamsID=NHLTeams.TeamID
Left JOIN Countries
ON Players.NationID=Countries.NationID
Left JOIN DraftTeam
ON Players.DraftID=DraftTeam.DraftID
WHERE Players.PlayerID=$iPlayerID
ORDER BY Players.LastName;
") or die(mysql_error());

while($row = mysql_fetch_array($oPlayerInfo))
{
Print “”;
Print “

”;
Print “”;
Print “";
Print “”;
Print “”;
Print “";
$DOB = $row[DOB]; //dd.mm.yyyy
$user_date = new DateTime($DOB);
$curr_date = new DateTime();
$age_cal = $curr_date->diff($user_date);
Print “”;
Print “”;
Print “”;
Print “”;
Print “”;
Print “”;
Print “”;
Print “”;
Print “”;
Print “”;
Print “”;
Print “”;
Print “”;
Print “”;
Print “”;
Print “";
Print “";
Print “”;
Print “”;
Print “”;
Print "";
Print “”;
Print “”;
Print "";
Print “”;
Print “

”.$row[‘FirstName’]." “.$row[‘LastName’].”

Birthdate:”.$row[‘DOB’]." Age: “.$age_cal->y;”
Nation:”.$row[‘Nation’].” CNGHL Team:”.$row[‘CNGHLRights’]. “
Position:”.$row[‘Position’]. “ Weight:”.$row[‘Weight’]. “
Height:”.$row[‘Height’]. “ NHL Team:”.$row[‘Team’]. “
Draft Year:”.$row[‘CNDraftYR’]." Draft Position:”.$row[‘CNDraftPOS’]."
Drafted By: “.$row[‘DrTeam’].” 
 
”;
Print “”;
}

$oPlayerStats = mysql_query("

SELECT SeasonStats.Sea, SeasonStats.TeamID, SeasonStats.GP, SeasonStats.Goals,
SeasonStats.Assists, SeasonStats.Points, SeasonStats.PlusMinus,
SeasonStats.Pim, SeasonStats.PP, SeasonStats.SH, SeasonStats.GW,
SeasonStats.GT, SeasonStats.S, Seasonteam.Team, SeasonStats.SubSeason
FROM SeasonStats
Left JOIN Seasonteam
On SeasonStats.TeamID=Seasonteam.TeamID
WHERE SeasonStats.PlayerID=$iPlayerID
ORDER BY SeasonStats.Sea ASC,SeasonStats.SubSeason ASC;
") or die(mysql_error());

Print ‘’;
Print “

”;
Print “”;
Print " ";
Print " ";
Print " ";
Print " ";
Print " ";
Print " ";
Print " ";
Print " ";
Print " ";
Print " ";
Print " ";
Print " ";
Print " ";

while($row = mysql_fetch_array($oPlayerStats))
{
Print “

”;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ ";
}
Print “
SeasonTeamGPGAPPIM+/-PPGSHGGWGGTGShots
”.$row[‘Sea’]."”.$row[‘Team’].””.$row[‘GP’].””.$row[‘Goals’].””.$row[‘Assists’].””.$row[‘Points’].””.$row[‘Pim’].””.$row[‘PlusMinus’].””.$row[‘PP’].””.$row[‘SH’].””.$row[‘GW’].””.$row[‘GT’].””.$row[‘S’].”
”;

$oPlayerStats = mysql_query("

SELECT SeasonStats.Sea, SeasonStats.TeamID, SeasonStats.GP, SeasonStats.Goals,
SeasonStats.Assists, SeasonStats.Points, SeasonStats.PlusMinus,
SeasonStats.Pim, SeasonStats.PP, SeasonStats.SH, SeasonStats.GW,
SeasonStats.GT, SeasonStats.S, Seasonteam.Team, SUM(SeasonStats.Goals) AS Goals_Total, SUM(SeasonStats.Assists) AS Assists_Total, SUM(SeasonStats.GP) As Games_Total, SUM(SeasonStats.Points) AS Points_Total, SUM(SeasonStats.Pim) AS Penalty_Total, SUM(SeasonStats.PlusMinus) AS PlusMinus_Total, SUM(SeasonStats.PP) AS Powerplay_Total, SUM(SeasonStats.SH) AS SH_Total, SUM(SeasonStats.GW) AS GW_Total, SUM(SeasonStats.GT) AS GT_Total, SUM(SeasonStats.S) AS Shots_Total
FROM SeasonStats
Left JOIN Seasonteam
On SeasonStats.TeamID=Seasonteam.TeamID
WHERE SeasonStats.PlayerID=$iPlayerID
ORDER BY SeasonStats.Sea
") or die(mysql_error());

Print “

”;
Print “”;
Print " ";
Print " ";
Print " ";
Print " ";
Print " ";
Print " ";
Print " ";
Print " ";
Print " ";
Print " ";
Print " ";
Print " ";
Print " ";

while($row = mysql_fetch_array($oPlayerStats))
{
Print “

”;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
}
Print “
SeasonTeamGPGAPPIM+/-PPGSHGGWGGTGShots
”.$row[’-’]."”.$row[’-’].””.$row[‘Games_Total’].””.$row[‘Goals_Total’].””.$row[‘Assists_Total’].””.$row[‘Points_Total’].””.$row[‘Penalty_Total’].””.$row[‘PlusMinus_Total’].””.$row[‘Powerplay_Total’].””.$row[‘SH_Total’].””.$row[‘GW_Total’].””.$row[‘GT_Total’].””.$row[‘Shots_Total’].”
”;
Print “
”;
$oPlayerTrans = mysql_query(”
SELECT Transtype.Transtype, TransFrom.TransFrom, TransTo.TransTo, Transactions.Transdate, Transactions.Transtime, Transactions.Season, Players.PlayerID
FROM Transtype
LEFT JOIN TransTo
LEFT JOIN TransFrom
LEFT JOIN Players
LEFT JOIN Transactions
ON Players.PlayerID = Transactions.PlayerID
ON TransFrom.TransFromID = Transactions.TransFromID
ON TransTo.TransToID = Transactions.TransToID
ON Transtype.TranstypeID = Transactions.TranstypeID
WHERE Players.PlayerID=$iPlayerID
ORDER BY Transactions.Transdate;
;
") or die(mysql_error ());
Print ‘’;
Print “”;
Print “”;
Print " ";
Print " ";
Print " ";
Print " ";
Print " “;
while($row = mysql_fetch_array($oPlayerTrans))
{
Print “”;
Print “ “;
Print “ “;
Print “ “;
Print “ “;
Print “ ";}
Print "</table>";

$oPlayerContracts = mysql_query("

SELECT Contracts.PlayerID, Contracts.Season, ContractID.ContractL, Contracts.ContractM, ContractTeam.Team
FROM ContractID
LEFT JOIN ContractTeam
LEFT JOIN Players
LEFT JOIN Contracts
ON Players.PlayerID = Contracts.PlayerID
ON ContractTeam.ContractteamID = Contracts.ContractteamID
ON ContractID.ContractID = Contracts.ContractID
WHERE Players.PlayerID=$iPlayerID
ORDER BY Contracts.Season;
;
") or die(mysql_error ());

Print “

Type of TransactionFromToDateSeason
”.$row[‘Transtype’].””.$row[‘TransFrom’].””.$row[‘TransTo’].””.$row[‘Transdate’].””.$row[‘Season’].”
”;
Print “”;
Print " ";
Print " ";
Print " ";
Print " “;
while($row = mysql_fetch_array($oPlayerContracts))
{
Print “”;
Print “ “;
Print “ ";
$unitcost=number_format($row[‘ContractM’]);
Print " “;
Print “ ";}
Print “
SeasonLenght$Team
”.$row[‘Season’].””.$row[‘ContractL’].”$ “.$unitcost.””.$row[‘Team’].”
”; ?> [/php]

take the ; off of orderby.

I tried that, but I get the same error.

You’ve got an extra where you deleted the login info for the server.

[php]mysql_connect(""", “”, “”) or die(mysql_error());
mysql_select_db("") or die(mysql_error());[/php] The semi colon at the end of this line?

its not the reason for the error. is $ playerid a number or a string?

PlayerID is a number that pulls from the mysql database do pick the specific player.

im assuming that theres a form somewhere. are you selecting the iplayerid? if so, verify that its getting sent to the 2nd page. may need to change it to post instead of get.

I changed it to post and uploaded I get the same error as I did before. I got this error after adding more tables to my document. The following code works fine, but when I add more to the document I get the error.[php]

}
td img {
vertical-align: top;
}

CNGHL Database <?php // Connects to your Database mysql_connect("", "", "") or die(mysql_error()); mysql_select_db("cnghldb") or die(mysql_error()); //Get PlayerID from URL $iPlayerID = $_GET["PlayerID"]; $iNationID = $_GET["NationID"]; $oPlayerInfo = mysql_query(" SELECT Players.PlayerID, Players.FirstName, Players.LastName, Players.Position, Players.Height, Players.Weight, Players.DOB, CNGHLTeams.CNGHLRights, NHLTeams.Team, Players.CNDraftYR, DraftTeam.DraftID, Players.CNDraftPOS, Countries.Nation, Players.NationID, DraftTeam.DrTeam FROM Players Left JOIN CNGHLTeams ON Players.CNGHLID=CNGHLTeams.CNGHLID Left JOIN NHLTeams ON Players.TeamsID=NHLTeams.TeamID Left JOIN Countries ON Players.NationID=Countries.NationID Left JOIN DraftTeam ON Players.DraftID=DraftTeam.DraftID WHERE Players.PlayerID=$iPlayerID ORDER BY Players.LastName; ") or die(mysql_error()); while($row = mysql_fetch_array($oPlayerInfo)) { Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; $DOB = $row[DOB]; //dd.mm.yyyy $user_date = new DateTime($DOB); $curr_date = new DateTime(); $age_cal = $curr_date->diff($user_date); Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print ""; Print "

".$row['FirstName']." ".$row['LastName']."

Birthdate:".$row['DOB']." Age: ".$age_cal->y;"
"; Print "
Nation:".$row['Nation']." CNGHL Team:".$row['CNGHLRights']. "
Position:".$row['Position']. " Weight:".$row['Weight']. "
Height:".$row['Height']. " NHL Team:".$row['Team']. "
Draft Year:".$row['CNDraftYR']." Draft Position:".$row['CNDraftPOS']."
Drafted By: ".$row['DrTeam']." 
 
"; Print ""; } $oPlayerStats = mysql_query(" SELECT SeasonStats.Sea, SeasonStats.TeamID, SeasonStats.GP, SeasonStats.Goals, SeasonStats.Assists, SeasonStats.Points, SeasonStats.PlusMinus, SeasonStats.Pim, SeasonStats.PP, SeasonStats.SH, SeasonStats.GW, SeasonStats.GT, SeasonStats.S, Seasonteam.Team, SeasonStats.SubSeason FROM SeasonStats Left JOIN Seasonteam On SeasonStats.TeamID=Seasonteam.TeamID WHERE SeasonStats.PlayerID=$iPlayerID ORDER BY SeasonStats.Sea ASC,SeasonStats.SubSeason ASC; ") or die(mysql_error()); Print ''; Print "

"; Print ""; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; while($row = mysql_fetch_array($oPlayerStats)) { Print ""; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; } Print "
SeasonTeamGPGAPPIM+/-PPGSHGGWGGTGShots
".$row['Sea']."".$row['Team']."".$row['GP']."".$row['Goals']."".$row['Assists']."".$row['Points']."".$row['Pim']."".$row['PlusMinus']."".$row['PP']."".$row['SH']."".$row['GW']."".$row['GT']."".$row['S']."
"; $oPlayerStats = mysql_query(" SELECT SeasonStats.Sea, SeasonStats.TeamID, SeasonStats.GP, SeasonStats.Goals, SeasonStats.Assists, SeasonStats.Points, SeasonStats.PlusMinus, SeasonStats.Pim, SeasonStats.PP, SeasonStats.SH, SeasonStats.GW, SeasonStats.GT, SeasonStats.S, Seasonteam.Team, SUM(SeasonStats.Goals) AS Goals_Total, SUM(SeasonStats.Assists) AS Assists_Total, SUM(SeasonStats.GP) As Games_Total, SUM(SeasonStats.Points) AS Points_Total, SUM(SeasonStats.Pim) AS Penalty_Total, SUM(SeasonStats.PlusMinus) AS PlusMinus_Total, SUM(SeasonStats.PP) AS Powerplay_Total, SUM(SeasonStats.SH) AS SH_Total, SUM(SeasonStats.GW) AS GW_Total, SUM(SeasonStats.GT) AS GT_Total, SUM(SeasonStats.S) AS Shots_Total FROM SeasonStats Left JOIN Seasonteam On SeasonStats.TeamID=Seasonteam.TeamID WHERE SeasonStats.PlayerID=$iPlayerID ORDER BY SeasonStats.Sea ") or die(mysql_error()); Print ""; Print ""; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; while($row = mysql_fetch_array($oPlayerStats)) { Print ""; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; Print " "; } Print "
SeasonTeamGPGAPPIM+/-PPGSHGGWGGTGShots
".$row['-']."".$row['-']."".$row['Games_Total']."".$row['Goals_Total']."".$row['Assists_Total']."".$row['Points_Total']."".$row['Penalty_Total']."".$row['PlusMinus_Total']."".$row['Powerplay_Total']."".$row['SH_Total']."".$row['GW_Total']."".$row['GT_Total']."".$row['Shots_Total']."
"; Print "
"; $oPlayerTrans = mysql_query(" SELECT Transtype.Transtype, TransFrom.TransFrom, TransTo.TransTo, Transactions.Transdate, Transactions.Transtime, Transactions.Season, Players.PlayerID FROM Transtype LEFT JOIN TransTo LEFT JOIN TransFrom LEFT JOIN Players LEFT JOIN Transactions ON Players.PlayerID = Transactions.PlayerID ON TransFrom.TransFromID = Transactions.TransFromID ON TransTo.TransToID = Transactions.TransToID ON Transtype.TranstypeID = Transactions.TranstypeID WHERE Players.PlayerID=$iPlayerID ORDER BY Transactions.Transdate; ; ") or die(mysql_error ()); Print ''; Print ""; Print ""; Print " "; Print " "; Print " "; Print " "; Print " "; while($row = mysql_fetch_array($oPlayerTrans)) { Print ""; Print " "; Print " "; Print " "; Print " "; Print " ";} Print "
Type of TransactionFromToDateSeason
".$row['Transtype']."".$row['TransFrom']."".$row['TransTo']."".$row['Transdate']."".$row['Season']."
"; $oPlayerContracts = mysql_query(" SELECT Contracts.PlayerID, Contracts.Season, ContractID.ContractL, Contracts.ContractM, ContractTeam.Team FROM ContractID LEFT JOIN ContractTeam LEFT JOIN Players LEFT JOIN Contracts ON Players.PlayerID = Contracts.PlayerID ON ContractTeam.ContractteamID = Contracts.ContractteamID ON ContractID.ContractID = Contracts.ContractID WHERE Players.PlayerID=$iPlayerID ORDER BY Contracts.Season; ; ") or die(mysql_error ()); Print "

"; Print ""; Print " "; Print " "; Print " "; Print " "; while($row = mysql_fetch_array($oPlayerContracts)) { Print ""; Print " "; Print " "; $unitcost=number_format($row['ContractM']); Print " "; Print " ";} Print "
SeasonLenght$Team
".$row['Season']."".$row['ContractL']."$ ".$unitcost."".$row['Team']."
"; ?> [/php]

This code works, but when I added the extras to it is when I get the error.

go back to what works and add in 1 peice until you get the error. also make sure that the column names are correct.

Thanks, I will give that a try. :slight_smile:

That ended up working, now I just have formatting issues to deal with.

Thanks again for your help

Glad you got it figured out. topic marked solved.

Sponsor our Newsletter | Privacy Policy | Terms of Service