Hello everyone, I'm not sure what is causing this issue or what I can do about it.
I have a data class and one of the methods is query:
PHP Code:
function query($Query_String) {
$this->Query_ID = mysql_query($Query_String,$this->Link_ID);
$this->Row = 0;
$this->Errno = mysql_errno();
$this->Error = mysql_error();
if (! $this->Query_ID) {
$this->halt("Invalid SQL: " . $Query_String);
}
return $this->Query_ID;
}
This works great and I have used it many times.
I also have another class that uses the data class.
Only one method of this other class is having an issue with the data class.
Here is the relevant snippet:
PHP Code:
// update skills, styles, and attributes if bcontinue == 1
if ($bcontinue == 1) {
// calculate remaining tp
$mynewtp = $this->tp - $myspenttp;
$dataf = new Data; // get db handle to db
// update attributes
$dataf->query("UPDATE fighters SET strength=$mystr, speed=$myspe, agility=$myagi, stamina=$mysta, endurance=$myend, flexibility=$myflx, tp=$mynewtp WHERE id=$this->id");
// update styles
for ($ic = 0; $ic < count($mystyles); $ic++) {
if (round($mystyles[$ic]['rank'],2) <> round($mystyleinfo[($mystyles[$ic]['id'] - 1)]['rank'],2)) {
$dataf->query("UPDATE fighter_styles SET rank = " . round($mystyleinfo[($mystyles[$ic]['id'] - 1)]['rank'],2) . " WHERE id = " . $mystyles[$ic]['fighterstyleid'] . " and fighter_id = $this->id");
}
// update skills
$myskills = $this->getSkills($mystyles[$ic]['id']);
for ($ic2 = 0; $ic2 < count($myskills); $ic2++) {
$mynewskill = sanitize_int($skills["skill-" . $myskills[$ic2]['fighterskill_id']]);
if ($mynewskill <> $myskills[$ic2]['skill_value']) {
$dataf->query("UPDATE fighter_skills SET value = " . round($mynewskill,2) . " WHERE id = " . $myskills[$ic2]['fighterskill_id'] . " and fighter_id = $this->id");
}
}
}
// reload stats
$this->set_stats($this->id);
}
The issue is the inner for loop (for ($ic2 = 0; $ic2 < count($myskills); $ic2++) {)
When it executes the data query method ($dataf->query("UPDATE fighter_skills SET value = " . round($mynewskill,2) . " WHERE id = " . $myskills[$ic2]['fighterskill_id'] . " and fighter_id = $this->id")
it works for the first iteration of the loop, but every other iteration creates the invalid sql error from the data class.
However, if I copy and paste the sql that generates the invalid sql error into mysql it works with no issues so the sql syntax is correct.
To help debug I added:
print "$Query_String<br />";
print "QueryID " . $this->Query_ID . "<br>";
print "ErrNo: " . $this->Errno . "<br>";
print "Error: " . $this->Error . "<br>";
print "LinkID: " . $this->Link_ID . "<br>";
to the query method and this is the result:
UPDATE fighter_skills SET value = 2 WHERE id = 49 and fighter_id = 91
QueryID 0
ErrNo: 0
Error:
LinkID: Resource id #31
UPDATE fighter_skills SET value = 2 WHERE id = 50 and fighter_id = 91
QueryID 0
ErrNo: 0
Error:
LinkID: Resource id #31
Error: Database error - : Invalid SQL: UPDATE fighter_skills SET value = 2 WHERE id = 50 and fighter_id = 91 in /home/league/public_html/classes/class.Data.php on line194
Any ideas on what may be causing this to error out on any iteration of the inner for loop after the first?
Many thanks for the help.