scorpiious Posted April 27, 2007 Share Posted April 27, 2007 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? Quote Link to comment Share on other sites More sharing options...
veridicus Posted April 27, 2007 Share Posted April 27, 2007 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) ."', ... Quote Link to comment Share on other sites More sharing options...
scorpiious Posted April 27, 2007 Author Share Posted April 27, 2007 what about $cblevel? thats a string too any its not working Quote Link to comment Share on other sites More sharing options...
veridicus Posted April 27, 2007 Share Posted April 27, 2007 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. Quote Link to comment Share on other sites More sharing options...
scorpiious Posted April 27, 2007 Author Share Posted April 27, 2007 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? Quote Link to comment Share on other sites More sharing options...
bsprogs Posted April 27, 2007 Share Posted April 27, 2007 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); Quote Link to comment Share on other sites More sharing options...
scorpiious Posted April 27, 2007 Author Share Posted April 27, 2007 nvm stupid mistake, i didnt add [0] 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.