Jump to content
MakeWebGames

Recommended Posts

Posted

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();
?>
Posted

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;
Posted

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 :)

Posted

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 ?

Posted

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();
?>
Posted
<?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();
?>
Posted

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;
Posted

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();
?>
Posted

you still do not have the correct Step 2

You have

$stat=$statnames(''. $_POST['statselect'] .'');

 

not

$stat=$statnames[''.$_POST['statselect'].''];
  • 2 weeks later...

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.   Paste as plain text instead

  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...