Gofast77 Posted June 18, 2014 Report Share Posted June 18, 2014 Hi guys, There are some days I wanted to add fields for the ranks (description, etc) but I got this error : Error updating the rank: 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 'Pilot' at line 3 Can you help me ? Thanks, Gofast Quote Link to comment Share on other sites More sharing options...
magicflyer Posted June 18, 2014 Report Share Posted June 18, 2014 Can you please copy down your SQL query? Usually it has something to do with the misconception a lot of people have of when to use ` and '. `` is used around SQL variables, while '' is used around php variables. As a matter of fact, none of them are really necessary but do a lot to toughen up protection against SQL injection. Quote Link to comment Share on other sites More sharing options...
Gofast77 Posted June 18, 2014 Author Report Share Posted June 18, 2014 class RanksData extends CodonData { public function getranks() { $sql = "SELECT * FROM " . TABLE_PREFIX . "ranks ORDER BY minhours"; return DB::get_results($sql); } public function getaircrafts($rankid) { $sql= "SELECT distinct icao FROM " . TABLE_PREFIX . "aircraft WHERE minrank=" . $rankid; return DB::get_results($sql); } static $lasterror; /** * Return information about the rank, given the ID */ public static function getRankInfo($rankid) { $sql = 'SELECT * FROM '.TABLE_PREFIX.'ranks WHERE rankid='.$rankid; return DB::get_row($sql); } /** * Returns all the ranks, and the total number of pilots * on each rank */ public static function getAllRanks() { $allranks = CodonCache::read('all_ranks'); if($allranks === false) { $sql = 'SELECT r.*, (SELECT COUNT(*) FROM '.TABLE_PREFIX.'pilots WHERE rank=r.rank) as totalpilots FROM ' .TABLE_PREFIX.'ranks r ORDER BY r.minhours ASC'; $allranks = DB::get_results($sql); CodonCache::write('all_ranks', $allranks, 'long'); } return $allranks; } public static function getRankImage($rank) { $sql = 'SELECT `rankimage` FROM '.TABLE_PREFIX.'ranks WHERE rank="'.$rank.'"'; return DB::get_var($sql); } /** * Get the level the passed rank is in the list */ public static function getRankLevel($rankid) { if($rankid == 0) { return 0; } $all_ranks = self::getAllRanks(); $i=0; foreach($all_ranks as $rank) { $i++; if($rank->rankid == $rankid) { return $i; } } return 0; } /** * Give the number of hours, return the next rank */ public static function getNextRank($hours) { $sql = "SELECT * FROM ".TABLE_PREFIX."ranks WHERE minhours>$hours ORDER BY minhours ASC LIMIT 1"; return DB::get_row($sql); } /** * Add a ranking. This will automatically call * CalculatePilotRanks() at the end */ public static function addRank($title, $minhours, $imageurl, $description, $payrate, $exams, $briefing) { $minhours = intval($minhours); $payrate = floatval($payrate); $sql = "INSERT INTO ".TABLE_PREFIX."ranks (rank, rankimage, minhours, description, payrate, exams, briefing) VALUES('$title', '$imageurl', '$description', '$minhours', '$payrate','$exams', '$briefing')"; $ret = DB::query($sql); if(DB::$errno == 1062) { self::$lasterror = 'This already exists'; return false; } CodonCache::delete('all_ranks'); self::CalculatePilotRanks(); return true; } /** * Update a certain rank */ public static function updateRank($rankid, $title, $minhours, $imageurl, $description, $payrate, $exams, $briefing) { $minhours = intval($minhours); $payrate = floatval($payrate); $sql = "UPDATE ".TABLE_PREFIX."ranks SET rank='$title', rankimage='$imageurl', minhours='$minhours', description='$description', payrate='$payrate', exams='$exams', briefing='$briefing' WHERE rankid=$rankid"; $res = DB::query($sql); if(DB::errno() != 0) return false; CodonCache::delete('all_ranks'); self::CalculatePilotRanks(); return true; } /** * Delete a rank, and then recalculate */ public static function deleteRank($rankid) { $sql = 'DELETE FROM '.TABLE_PREFIX.'ranks WHERE rankid='.$rankid; DB::query($sql); if(DB::errno() != 0) return false; CodonCache::delete('all_ranks'); self::CalculatePilotRanks(); return true; } /** * Go through each pilot, check their hours, and see where they * stand in the rankings. If they are above the minimum hours * for that rank level, then make $last_rank that text. At the * end, update that */ public static function calculatePilotRanks() { /* Don't calculate a pilot's rank if this is set */ if(Config::Get('RANKS_AUTOCALCULATE') === false) { return; } $allranks = self::getAllRanks(); $pilots = PilotData::getAllPilots(); if(count($pilots) == 0 || !is_array($pilots)) { return; } foreach($pilots as $pilot) { $last_rank = ''; $pilothours = intval($pilot->totalhours); if(Config::Get('TRANSFER_HOURS_IN_RANKS') == true) { $pilothours += $pilot->transferhours; } $i = 1; foreach($allranks as $rank) { if($pilothours >= intval($rank->minhours)) { $rank_level = $i; $last_rank = $rank->rank; $last_rankid = $rank->rankid; } $i++; } $update = array( 'rankid' => $last_rankid, 'rank' => $last_rank, 'ranklevel' => $rank_level, ); PilotData::updateProfile($pilot->pilotid, $update); } } public static function calculateUpdatePilotRank($pilotid) { /* Don't calculate a pilot's rank if this is set */ if(Config::Get('RANKS_AUTOCALCULATE') == false) { return; } $pilotid = intval($pilotid); $allranks = self::GetAllRanks(); $pilot = PilotData::GetPilotData($pilotid); $pilothours = $pilot->totalhours; if(Config::Get('TRANSFER_HOURS_IN_RANKS') == true) { $pilothours += $pilot->transferhours; } $i = 0; foreach($allranks as $rank) { $i++; if($pilothours >= intval($rank->minhours)) { $rank_level = $i; $last_rank = $rank->rank; $last_rankid = $rank->rankid; } } $update = array( 'rankid' => $last_rankid, 'rank' => $last_rank, 'ranklevel' => $rank_level, ); PilotData::updateProfile($pilot->pilotid, $update); } } Quote Link to comment Share on other sites More sharing options...
Gofast77 Posted June 18, 2014 Author Report Share Posted June 18, 2014 I also have this error : Warning: Missing argument 8 for RanksData::updateRank() Quote Link to comment Share on other sites More sharing options...
magicflyer Posted June 18, 2014 Report Share Posted June 18, 2014 Try the following replacement for that $sql over to where you added the description parameter. $sql = "UPDATE `".TABLE_PREFIX."ranks` SET `rank`='$title', `rankimage`='$imageurl', `minhours`='$minhours', `description`='$description', `payrate`='$payrate', `exams`='$exams', `briefing`='$briefing' WHERE `rankid`='$rankid'"; Also make sure that wherever you're passing in these parameters(Probably the admin module for ranks), you have the same number of arguments as parameters. Parameters are the variables in the function($var1, $var2) where the function does something. Arguments are the variables in the function($var1, $var2) where you're calling the function that does something. Quote Link to comment Share on other sites More sharing options...
Gofast77 Posted June 18, 2014 Author Report Share Posted June 18, 2014 The error is the same Quote Link to comment Share on other sites More sharing options...
magicflyer Posted June 18, 2014 Report Share Posted June 18, 2014 The error is the same Show me where you're calling the function(It should be in the admin's modules directory. Just the line, not the entire module. Quote Link to comment Share on other sites More sharing options...
Gofast77 Posted June 18, 2014 Author Report Share Posted June 18, 2014 Excuse me I have two website (one in French and one in English, I confused the two). The SQL error exists more but the other if and when I change, there is nothing changes... Quote Link to comment Share on other sites More sharing options...
magicflyer Posted June 19, 2014 Report Share Posted June 19, 2014 Excuse me I have two website (one in French and one in English, I confused the two). The SQL error exists more but the other if and when I change, there is nothing changes... I don't think you understand what I mean, which probably means you didn't modify the argument function. The argument function is found in the admin/core/modules folder under whichever module you added the 'description' input box. Right there when you find the if(this->post->action == 'editRank') or something of the sort..., you should also find a statement to be executed that refers to the function that you have modified. It should look like: myFunction($this->post->var1, $this->post->var2, $this->post->var3, ...) Be sure that $this->post->description is found in that function in the correct order as the parameter function found in the code above: public static function updateRank($rankid, $title, $minhours, $imageurl, $description, $payrate, $exams, $briefing) Quote Link to comment Share on other sites More sharing options...
Gofast77 Posted June 19, 2014 Author Report Share Posted June 19, 2014 That's it, thanks. I wanted to add one final fields and I have this error : Error updating the rank: 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 't fly without the presence of an instructor.', `payrate`='25', `exams`='-', `bri' at line 2 Quote Link to comment Share on other sites More sharing options...
magicflyer Posted June 19, 2014 Report Share Posted June 19, 2014 That's it, thanks. I wanted to add one final fields and I have this error : Error updating the rank: 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 't fly without the presence of an instructor.', `payrate`='25', `exams`='-', `bri' at line 2 Can you copy&paste that edited SQL statement please? Just the SQL Statement you modified. Quote Link to comment Share on other sites More sharing options...
Gofast77 Posted June 19, 2014 Author Report Share Posted June 19, 2014 public static function updateRank($rankid, $title, $minhours, $imageurl, $conditions, $description, $payrate, $exams, $briefing) { $minhours = intval($minhours); $payrate = floatval($payrate); $sql = "UPDATE `".TABLE_PREFIX."ranks` SET `rank`='$title', `rankimage`='$imageurl', `minhours`='$minhours', `conditions`='$conditions', `description`='$description', `payrate`='$payrate', `exams`='$exams', `briefing`='$briefing' WHERE `rankid`='$rankid'"; $res = DB::query($sql); if(DB::errno() != 0) return false; CodonCache::delete('all_ranks'); self::CalculatePilotRanks(); return true; } Quote Link to comment Share on other sites More sharing options...
magicflyer Posted June 19, 2014 Report Share Posted June 19, 2014 My eyes are a little blurry, but I don't think there is anything wrong with the syntax. Did you make sure to add those fields in the SQL Database as well for the phpvms_ranks table?(Both the conditions, and description) Quote Link to comment 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.