Customizing SMF > SMF Coding Discussion
SMFPets Mod
Ice_Drake:
Hi, I have been trying to get an old mod called SMFPets to work for SMF 2.0+. So far, I got most of the codes converted to work correctly now. Except now, I am stuck at a strange error. I don't know where the problem is coming from.
--- Code: ---//Store the values back into the database(very important)
function store_values() {
global $db_prefix, $smcFunc;
$smcFunc['db_query']('', "
UPDATE {db_prefix}shop_pets
SET name = {string:name},
level = {int:level},
curap = {int:curap},
maxap = {int:maxap},
happy = {int:happy},
desc = {string:desc},
hunger = {int:hunger},
age = {int:age},
training = {int:training},
trainingend = {string:trainingend},
ownerid = {int:ownerid}
WHERE pet_id = {int:pet_id}",
array(
'name' => $this->name,
'level' => $this->level,
'curap' => $this->curap,
'maxap' => $this->maxap,
'happy' => $this->happy,
'desc' => $this->desc,
'hunger' => $this->hunger,
'age' => $this->age,
'training' => $this->training,
'trainingend' => $this->trainingend,
'ownerid' => $this->ownerid,
'pet_id' => $this->id
));
}
--- End code ---
This is the error message I got:
Database 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 'desc = 'These Lions are the King of the Beasts!',
hunger = 9,
' at line 7
File: /home/nasserve/public_html/Sources/shop/pet_engine.php
Line: 321
Note: It appears that your database may require an upgrade. Your forum's files are currently at version SMF 2.0.2, while your database is at version 2.0. The above error might possibly go away if you execute the latest version of upgrade.php.
Trying to isolate the problem, I am able to get it to work if I take out:
--- Code: ---desc = {string:desc},
--- End code ---
and:
--- Code: ---'desc' => $this->desc,
--- End code ---
Problem is that I need to keep those lines. Thus, I am at a lost. I don't see syntax error, so it must be logic error. What am I missing?
Ice_Drake:
After encountering the similar problem elsewhere again, I am able to narrow down to the source of the problem. The problem is coming from "desc". In fact, DESC is a reserved word. Since I have a field named desc, I must quote it in order to use it. If not, the query string would end up in parsing error.
K@:
As this is about coding, I've been a bit devilish and moved this to the Coding board.
You might get a better response, here. :)
Ice_Drake:
Thanks, but I already found my answer as I mentioned above.
K@:
Indeed. But, it might help others who have the same thing going-on. ;)
Navigation
[0] Message Index
[#] Next page
Go to full version