corruptcity || skalman Posted October 22, 2009 Posted October 22, 2009 Hi i was wondering if anyone would be able to help me finish off my mod the coding has been done im just having problems with my querys. Any help will be appreciated and need any other info just ask [mysql]CREATE TABLE IF NOT EXISTS `implants` ( `statis` int(11) NOT NULL, `userid` int(11) NOT NULL, `stat` text NOT NULL, `amount` decimal(11,4) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1;[/mysql] <?php include "globals.php"; $statnames=array( 'Strength' => 'strength', 'Agility' => 'agility', 'Guard' => 'guard', 'Labour' => 'labour'); $_POST['statselect']=abs((int) $_POST['statselect']); if($_POST['statselect']) { $stat=$statnames[$_POST['statselect']]; if(!$statselect) { die("This stat cannot be withdrawn."); } { $withdrawn=($stat/5)*100; $db->query("UPDATE userstats SET '{$stat}' = '{$stat}' - $withdrawn WHERE 'userid' = ".$userid.""); $db->query("Insert into implants (statid, userid, stat, amount) VALUES ('',".$ir['userid'].",'$statselect','$withdrawn')"); $inc=$ir[$stat]-$withdraw; if($statselect=="strength") { print "You Safety Managed to fill the Stat Implant with some of your strength. You have lost {$withdrawn} strength from this process. You now have {$inc} strength."; } elseif($statselect=="agility") { print "You Safety Managed to fill the Stat Implant with some of your Agility. You have lost {$withdrawn} agility from this process. You now have {$inc} agility."; } elseif($statselect=="guard") { print "You Safety Managed to fill the Stat Implant with some of your Guard. You have gained {$withdrawn} guard from this process. You now have {$inc} guard."; } elseif($statselect=="labour") { print "You Safety Managed to fill the Stat Implant with some of your Labour. You have gained {$withdrawn} labour from this process. You now have {$inc} labour."; } elseif($statselect=="IQ") { print "You Safety Managed to fill the Stat Implant with some of your IQ. You have gained {$withdrawn} labour from this process. You now have {$inc}."; } print "<hr />"; $ir['stat']-=$_POST['withdrawn']; $ir[$stat]-=$withdrawn; } } $ir['strank']=get_rank($ir['strength'],'strength'); $ir['agirank']=get_rank($ir['agility'],'agility'); $ir['guarank']=get_rank($ir['guard'],'guard'); $ir['labrank']=get_rank($ir['labour'],'labour'); $ir['IQrank']=get_rank($ir['IQ'],'IQ'); print "Choose the stat you want to withdraw from. <form action='testeresi.php' method='post'> Stat: <select type='dropdown' name='statselect'> <option style='color:red;' value='Strength'>Strength (Have {$ir['strength']}, Ranked {$ir['strank']}) <option style='color:blue;' value='Agility'>Agility (Have {$ir['agility']}, Ranked {$ir['agirank']}) <option style='color:green;' value='Guard'>Guard (Have {$ir['guard']}, Ranked {$ir['guarank']}) <option style='color:brown;' value='Labour'>Labour (Have {$ir['labour']}, Ranked {$ir['labrank']}) <option style='color:Yellow;' value='Labour'>Labour (Have {$ir['IQ']}, Ranked {$ir['IQrank']}) </select> <input type='submit' value='withdraw' /></form>"; $h->endpage(); ?> Quote
Gucci Mane Posted October 23, 2009 Posted October 23, 2009 TRY: CREATE TABLE IF NOT EXISTS `implants` ( `statis` int(11) NOT NULL, `userid` int(11) NOT NULL, `stat` text(11) NOT NULL, `amount` decimal(11,4) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Quote
Curt Posted October 23, 2009 Posted October 23, 2009 lol... im pretty sure that text does not need (11) after it...thats for integers...(numbers).. Quote
Uridium Posted October 23, 2009 Posted October 23, 2009 try changing `statis` int(11) NOT NULL, to `statid` int(11) NOT NULL, Thats the only fault i can see. Too do this openup PHPMYADMIN select the table for implants click the pencil on statis and change to statid. Or you could always just change the statid on the Script to statis :) Quote
corruptcity || skalman Posted October 23, 2009 Author Posted October 23, 2009 yeah ive done that but its still not storing it in the db Quote
Uridium Posted October 23, 2009 Posted October 23, 2009 This line dont look right. $db->query("UPDATE userstats SET '{$stat}' = '{$stat}' - $withdrawn WHERE 'userid' = ".$userid.""); SET '{$stat}' = '{$stat}' <<< how does it know which stat it is your referring too ? Quote
corruptcity || skalman Posted October 23, 2009 Author Posted October 23, 2009 this is where it does it $statnames=array( 'Strength' => 'strength', 'Agility' => 'agility', 'Guard' => 'guard', 'Labour' => 'labour' 'IQ' => 'IQ',); $_POST['statselect']=abs((int) $_POST['statselect']); if($_POST['statselect']) { $stat=$statnames[$_POST['statselect']]; Quote
corruptcity || skalman Posted October 23, 2009 Author Posted October 23, 2009 update of code <?php include "globals.php"; $statnames=array( 'Strength' => 'strength', 'Agility' => 'agility', 'Guard' => 'guard', 'Labour' => 'labour', 'IQ' => 'IQ'); $_POST['statselect']=abs((int) $_POST['statselect']); if($_POST['statselect']) { $stat=$statnames($_POST['statselect']); $withdrawn=($stat/5)*100; $db->query("UPDATE userstats SET $stat=$stat-withdrawn WHERE userid={$r['userid']}"); $db->query("Insert into implants (statid, userid, stat, amount) VALUES ('',".$ir['userid'].",'$statselect','$withdrawn')"); if(!$statselect) { die("This stat cannot be withdrawn."); } { $inc=$ir[$stat]-$withdraw; if($statselect=="strength") { print "You Safety Managed to fill the Stat Implant with some of your strength. You have lost {$withdrawn} strength from this process. You now have {$inc} strength."; } elseif($statselect=="agility") { print "You Safety Managed to fill the Stat Implant with some of your Agility. You have lost {$withdrawn} agility from this process. You now have {$inc} agility."; } elseif($statselect=="guard") { print "You Safety Managed to fill the Stat Implant with some of your Guard. You have gained {$withdrawn} guard from this process. You now have {$inc} guard."; } elseif($statselect=="labour") { print "You Safety Managed to fill the Stat Implant with some of your Labour. You have gained {$withdrawn} labour from this process. You now have {$inc} labour."; } elseif($statselect=="IQ") { print "You Safety Managed to fill the Stat Implant with some of your IQ. You have gained {$withdrawn} labour from this process. You now have {$inc}."; } print "<hr />"; $ir['stat']-=$_POST['withdrawn']; $ir[$stat]-=$withdrawn; } } $ir['strank']=get_rank($ir['strength'],'strength'); $ir['agirank']=get_rank($ir['agility'],'agility'); $ir['guarank']=get_rank($ir['guard'],'guard'); $ir['labrank']=get_rank($ir['labour'],'labour'); $ir['IQrank']=get_rank($ir['IQ'],'IQ'); print "Choose the stat you want to withdraw from. <form action='testeresi.php' method='post'> Stat: <select type='dropdown' name='statselect'> <option style='color:red;' value='Strength'>Strength (Have {$ir['strength']}, Ranked {$ir['strank']}) <option style='color:blue;' value='Agility'>Agility (Have {$ir['agility']}, Ranked {$ir['agirank']}) <option style='color:green;' value='Guard'>Guard (Have {$ir['guard']}, Ranked {$ir['guarank']}) <option style='color:brown;' value='Labour'>Labour (Have {$ir['labour']}, Ranked {$ir['labrank']}) <option style='color:Yellow;' value='Labour'>Labour (Have {$ir['IQ']}, Ranked {$ir['IQrank']}) </select> <input type='submit' value='withdraw' /></form>"; $h->endpage(); ?> Quote
Joshua Posted October 23, 2009 Posted October 23, 2009 <?php include "globals.php"; $statnames=array( 'Strength' => 'strength', 'Agility' => 'agility', 'Guard' => 'guard', 'Labour' => 'labour'); $_POST['statselect']=abs((int) $_POST['statselect']); if($_POST['statselect']) { $stat=$statnames($_POST['statselect']); { $withdrawn=($stat/5)*100; $db->query("UPDATE userstats SET '{$stat}'='{$stat}'-$withdrawn WHERE 'userid'=".$userid.""); $db->query("Insert into implants (statid, userid, stat, amount) VALUES ('',".$ir['userid'].",'$statselect','$withdrawn')"); $inc=$ir[$stat]-$withdrawn; if($statselect=="strength") { print "You Safety Managed to fill the Stat Implant with some of your strength. You have lost {$withdrawn} strength from this process. You now have {$inc} strength."; } elseif($statselect=="agility") { print "You Safety Managed to fill the Stat Implant with some of your Agility. You have lost {$withdrawn} agility from this process. You now have {$inc} agility."; } elseif($statselect=="guard") { print "You Safety Managed to fill the Stat Implant with some of your Guard. You have gained {$withdrawn} guard from this process. You now have {$inc} guard."; } elseif($statselect=="labour") { print "You Safety Managed to fill the Stat Implant with some of your Labour. You have gained {$withdrawn} labour from this process. You now have {$inc} labour."; } elseif($statselect=="IQ") { print "You Safety Managed to fill the Stat Implant with some of your IQ. You have gained {$withdrawn} labour from this process. You now have {$inc}."; } else if(!$statselect) { die("This stat cannot be withdrawn."); } print "<hr />"; $ir['stat']-=$_POST['withdrawn']; $ir[$stat]-=$withdrawn; } } $ir['strank']=get_rank($ir['strength'],'strength'); $ir['agirank']=get_rank($ir['agility'],'agility'); $ir['guarank']=get_rank($ir['guard'],'guard'); $ir['labrank']=get_rank($ir['labour'],'labour'); $ir['IQrank']=get_rank($ir['IQ'],'IQ'); print "Choose the stat you want to withdraw from. <form action='testeresi.php' method='post'> Stat: <select type='dropdown' name='statselect'> <option style='color:red;' value='Strength'>Strength (Have {$ir['strength']}, Ranked {$ir['strank']}) <option style='color:blue;' value='Agility'>Agility (Have {$ir['agility']}, Ranked {$ir['agirank']}) <option style='color:green;' value='Guard'>Guard (Have {$ir['guard']}, Ranked {$ir['guarank']}) <option style='color:brown;' value='Labour'>Labour (Have {$ir['labour']}, Ranked {$ir['labrank']}) <option style='color:Yellow;' value='Labour'>Labour (Have {$ir['IQ']}, Ranked {$ir['IQrank']}) </select> <input type='submit' value='withdrawn' /></form>"; $h->endpage(); ?> Quote
fbiss Posted October 23, 2009 Posted October 23, 2009 Skalman, Looking at your recent update, Here are errors that jumped out at me. Step 1. Find: $_POST['statselect']=abs((int) $_POST['statselect']); If you look at your form, the values you are passing in the $_POST['statselect'] are strings (Strength, Agility, etc..) not numbers. The use of abs and int are number functions to validate that the number is a positive whole number. As this variable wont be used in the query, we do not need to validate it. So Remove the line entirely. -------------------------------------------------------- Step 2. FInd: $stat=$statnames($_POST['statselect']); You are trying to use the $statnames array as a function, and not as an array.. ie $statnames() should be $statnames[]. The reason that you are submitting $_POST['statselect'] in the form value is to find the correct array key in the $statnames array. Replace the line with: $stat=$statnames[''.$_POST['statselect'].'']; -------------------------------------------------------- Step 3 Find: if($_POST['statselect']) { We want to be sure that the $_POST['statselect'] is indeed in the $statnames array Replace with: if($_POST['statselect'] && array_key_exists(''.$_POST['statselect'].'',$statnames)) { -------------------------------------------------------- Step 4. Find: die("This stat cannot be withdrawn."); } { You forgot the else Replace with: die("This stat cannot be withdrawn."); } else { -------------------------------------------------------- Step 5. Find: $withdrawn=($stat/5)*100; Since $stat is derived from a string this will not work, you cannot use math functions on a string. however you can use the $stat as the array key in your $ir array. By Replacing it with: $withdrawn=($ir[''.$stat.'']/5)*100; But, you may want to change your math, as this will surely put someone in the negative for the chosen stat. If you are trying to subtract a certain percent, i suggest replacing it with this Suggestion: $wdperc= 20; //Change to the percent that you with like to withdrawl, EX. 20 would be 20% $withdrawn=$ir[''.$stat.'']*($wdperc/100); -------------------------------------------------------- Step 6. You use the variable $statselect , but it is not defined anywhere. Find ALL $statselect and replace them with $stat ------------------------------------------------------- Step 7. Find: $ir['stat']-=$_POST['withdrawn']; $ir[$stat]-=$withdrawn; Replace with: $ir[''.$stat.'']-=$withdrawn; Quote
corruptcity || skalman Posted October 23, 2009 Author Posted October 23, 2009 ok thanks for that fbiss but im getting error on line 56 which is else Quote
fbiss Posted October 23, 2009 Posted October 23, 2009 The changes i mentioned in my post, should have been applied to your latest post, not Immortalthugs post Quote
corruptcity || skalman Posted October 23, 2009 Author Posted October 23, 2009 now when i run it i get Fatal error: Function name must be a string in C:\xampp\htdocs\testeresi.php on line 13 Quote
corruptcity || skalman Posted October 24, 2009 Author Posted October 24, 2009 yeah i used my initative and changed that before posting on here and it still says error on line 13 Quote
corruptcity || skalman Posted October 24, 2009 Author Posted October 24, 2009 ok here it is it could of been that u gunganed it lol <?php include_once "globals.php"; $statnames=array( 'Strength' => 'strength', 'Agility' => 'agility', 'Guard' => 'guard', 'Labour' => 'labour', 'IQ' => 'IQ'); if($_POST['statselect'] && array_key_exists(''.$_POST['statselect'].'',$statnames)) { $stat=$statnames(''. $_POST['statselect'] .''); $wdperc= 5; //Change to the percent that you with like to withdrawl, EX. 20 would be 20% $withdrawn=$ir[''.$stat.'']*($wdperc/100); $db->query("UPDATE userstats SET $stat=$stat-withdrawn WHERE userid={$r['userid']}"); $db->query("Insert into implants (statid, userid, stat, amount) VALUES ('',".$ir['userid'].",'$stat ','$withdrawn')"); if(!$stat) { die("This stat cannot be withdrawn."); } else { $inc=$ir[$stat]-$withdraw; if($stat=="strength") { print "You Safety Managed to fill the Stat Implant with some of your strength. You have lost {$withdrawn} strength from this process. You now have {$inc} strength."; } elseif($stat=="agility") { print "You Safety Managed to fill the Stat Implant with some of your Agility. You have lost {$withdrawn} agility from this process. You now have {$inc} agility."; } elseif($stat=="guard") { print "You Safety Managed to fill the Stat Implant with some of your Guard. You have lost {$withdrawn} guard from this process. You now have {$inc} guard."; } elseif($stat=="labour") { print "You Safety Managed to fill the Stat Implant with some of your Labour. You have lost {$withdrawn} labour from this process. You now have {$inc} labour."; } elseif($stat=="IQ") { print "You Safety Managed to fill the Stat Implant with some of your IQ. You have lost {$withdrawn} labour from this process. You now have {$inc}."; } print "<hr />"; $ir[''.$stat.'']-=$withdrawn; } } $ir['strank']=get_rank($ir['strength'],'strength'); $ir['agirank']=get_rank($ir['agility'],'agility'); $ir['guarank']=get_rank($ir['guard'],'guard'); $ir['labrank']=get_rank($ir['labour'],'labour'); $ir['IQrank']=get_rank($ir['IQ'],'IQ'); print "Choose the stat you want to withdraw from. <form action='testeresi.php' method='post'> Stat: <select type='dropdown' name='statselect'> <option style='color:red;' value='Strength'>Strength (Have {$ir['strength']}, Ranked {$ir['strank']}) <option style='color:blue;' value='Agility'>Agility (Have {$ir['agility']}, Ranked {$ir['agirank']}) <option style='color:green;' value='Guard'>Guard (Have {$ir['guard']}, Ranked {$ir['guarank']}) <option style='color:brown;' value='Labour'>Labour (Have {$ir['labour']}, Ranked {$ir['labrank']}) <option style='color:orange;' value='IQ'>Labour (Have {$ir['IQ']}, Ranked {$ir['IQrank']}) </select> <input type='submit' value='withdraw' /></form>"; $h->endpage(); ?> Quote
fbiss Posted October 24, 2009 Posted October 24, 2009 you still do not have the correct Step 2 You have $stat=$statnames(''. $_POST['statselect'] .''); not $stat=$statnames[''.$_POST['statselect'].'']; Quote
corruptcity || skalman Posted October 24, 2009 Author Posted October 24, 2009 ah sorry i get it now it just that its very l8 here in the UK and im in need of sleep lol Quote
corruptcity || skalman Posted October 24, 2009 Author Posted October 24, 2009 ok got it to work thyvm FBISS Illusions and immortal thug u can all have +1 Quote
Zero-Affect Posted November 4, 2009 Posted November 4, 2009 Good job Fbiss was planning on giving this guy a hand but it's already taken care of, looks like a interesting mod good work. Quote
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.