Jump to content

php sql format help..


scorpiious

Recommended Posts

can someone tell me how to properly fix this? i dont know how to add strings or functions inside the query..

 

mysql_query("INSERT INTO userdata (ID, username, combat, overall, rank, xp, attack, defence, strength, hp, ranged, prayer, magic, cooking, woodcutting, fletching, fishing, firemaking, `crafting`, smithing, mining, herblore, agility, theiving, slayer, farming, runecraft, hunter, construction) VALUES ('NULL', '$_GET[user]', '$cblevel', 'parselvl(Overall)', 'parserank(Overall)', 'parsexp(Overall)', 'parselvl(Attack)', 'parselvl(Defence)', 'parselvl(Strength)', 'parselvl(Hitpoints)', 'parselvl(Ranged)', 'parselvl(Prayer)', 'parselvl(Magic)', 'parselvl(Cooking)', 'parselvl(Woodcutting)', 'parselvl(Fletching)', 'parselvl(Fishing)', 'parselvl(Firemaking)', 'parselvl(Crafting)', 'parselvl(Smithing)', 'parselvl(Mining)', 'parselvl(Herblore)', 'parselvl(Agility)', 'parselvl(Thieving)', 'parselvl(Slayer)', 'parselvl(Farming)', 'parselvl(Runecraft)', 'parselvl(Hunter)', 'parselvl(Construction)')");

 

the parts where it says parselvl are actually functions, how would i tell sql that?

Link to comment
Share on other sites

What you're looking for is string concatenation so functions are processed in PHP, then the result goes to mysql...

 

mysql_query("INSERT INTO userdata (ID, username, combat, overall, rank, xp, attack, defence, strength, hp, ranged, prayer, magic, cooking, woodcutting, fletching, fishing, firemaking, `crafting`, smithing, mining, herblore, agility, theiving, slayer, farming, runecraft, hunter, construction) VALUES ('NULL', '$_GET[user]', '$cblevel', '". parselvl(Overall) ."', '". parserank(Overall) ."', ...

 

Link to comment
Share on other sites

You can always end the string with double quotes and concatenate a variable just like a function call...

 

mysql_query("INSERT INTO userdata (ID, username, combat, overall, rank, xp, attack, defence, strength, hp, ranged, prayer, magic, cooking, woodcutting, fletching, fishing, firemaking, `crafting`, smithing, mining, herblore, agility, theiving, slayer, farming, runecraft, hunter, construction) VALUES ('NULL', '". $_GET[user] ."', '". $cblevel ."', '". parselvl(Overall) ."', '". parserank(Overall) ."', ...

 

BTW, you probably don't want to insert any GET values directly for security reasons.  At the very least pass it through the mysql_real_escape_string function.

Link to comment
Share on other sites

ok well, i tried the .'s and it worked but the calculation doesnt work, look i have this code to calculate the cblevel

 

$cblevelraw = ("0.32707" * parselvl(Attack)) + ("0.249" * parselvl(Defence)) + ("0.324" * parselvl(Strength)) + ("0.25" * parselvl(Hitpoints)) + ("0.124" * parselvl(Prayer));
$cblevel = explode(".",$cblevelraw);

 

why does it show up in the database as arr?

Link to comment
Share on other sites

Whenever I get an error using an array, or it doesn't give me the result I'm looking for, I'll always try to troubleshoot it using print_r().

 

After this line

$cblevel = explode(".",$cblevelraw);

type this and see what the values of the $cblevel array are.

print_r($cblevel);

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.