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? Link to comment https://forums.phpfreaks.com/topic/48995-php-sql-format-help/ 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) ."', ... Link to comment https://forums.phpfreaks.com/topic/48995-php-sql-format-help/#findComment-240020 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 Link to comment https://forums.phpfreaks.com/topic/48995-php-sql-format-help/#findComment-240023 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. Link to comment https://forums.phpfreaks.com/topic/48995-php-sql-format-help/#findComment-240041 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? Link to comment https://forums.phpfreaks.com/topic/48995-php-sql-format-help/#findComment-240046 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); Link to comment https://forums.phpfreaks.com/topic/48995-php-sql-format-help/#findComment-240049 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] Link to comment https://forums.phpfreaks.com/topic/48995-php-sql-format-help/#findComment-240116 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.