Jump to content

A little Help please?


SoireeExtreme

Recommended Posts

Hi I'm new to the forum, php, and mysql. I was wondering if someone could help me out a little bit. I have a script set up. But it doesn't work as I'd like it to. I'm creating an attack script. And what is to happen of course is to figure out who won and who lost. But it doesn't do that. I tells you that you have won every single time. And there have been plenty of times I should have lost. If anyone could help me out that would be great? Thanks!

Heres my script.

[color=maroon]
$update=$userstats3['atkskill']/10;
$update2=$playertwo3['atkskill']/10;

$atk1=$userstats3['atkskill']+$userstats3['defend'];
$atk2=$playertwo3['atkskill']+$playertwo3['defend'];

if($atk1>$atk2)
{
echo "<center><font color=#FFFFF face=Verdana size=1>You Won<P> Gained $update Skillpts<P><a href='index.php'>Back</a>";

$skill="update ac_users set atkskill=atkskill+'$update', numturns=numturns-'0' where playername='$player'";
mysql_query($skill);
}
else
if($atk2>$atk1)
{
echo "<center><font color=#FFFFF face=Verdana size=1>You Lose";

$skill2="update ac_users set atkskill=atkskill+'$update2' where ID='$playertwo3[ID]'";
mysql_query($skill2);[/color]
Link to comment
Share on other sites

Ok I tried what you said with this.

echo "$playertwo3[playername]";
echo "$playertwo3[atkskill]";
echo "$playertwo3[defend]";
echo "$atk2";

And everything came up blank except for echo "$atk2<br>"; It should the number 0 when I know it should show a different number.

I am using this...

$playertwo="SELECT * from ac_users where ID='$playerID'";
$playertwo2=mysql_query($playertwo) or die("Blah");
$playertwo3=mysql_fetch_array($playertwo2);

To get those things from the database. But as you already know its nothing getting anything. How would I about about fixing this problem?

I do know that $playertwo="SELECT * from ac_users where ID='$playerID'";  has this error  Notice: Undefined variable: playerID in c:\Inetpub\wwwroot\ac\attack.php on line 98

But I'm not concerned about that unless its causing the problems? But that error only shows on my computer. But when I upload it to the web its fine. But still has the attack problems.

Is there anything else you can or anyone else can tell me to help me figure this problem out?


EDIT:: And note that everything for the other user $userstats3 comes out fine. Playertwo is the one I"m having problems with.
Link to comment
Share on other sites

That error is your problem.. $playerID was never set to anything.  If it's not set to any value, you can't use it to fetch data from the database.

Take a look at where you set $playerID.  There will be a mistake there, probably a typo, causing it not to be set.

The reason the error doesn't show when you upload it is just because the server is configured not to show notices.  It's not really an "error", it's just a "notice", meaning you might want to take a look at it.  The problem is still there even when it doesn't show the message.
Link to comment
Share on other sites

No problems.. I will try again :)

In your database query, you are fetching the player whose id is $playerID.  But, you have not told php what $playerID is.  So it says "undefined value".

It's like you are saying to php "Fetch the player from the database", and it says "Which player?  You haven't told me which one you want!"

The questions to ask to solve the problem are:

1.  How does my script know who player 2 is?  Does it get the value from $_GET, $_POST or $_REQUEST?
2.  What variable name is player 2's id stored in?  Is there a line like "$playerID = $_GET['playerID']" ?
3.  Why is $playerID not set to player 2's id?  (You know it's not set correctly because php said "undefined value" when you tried to use it)

Or you can post the whole script here and we will take a look :)
Link to comment
Share on other sites

Here is the script.
[color=maroon]
<?php
if (isset($_SESSION['player']))
  {
    $player=$_SESSION['player'];
    $userstats="SELECT * from ac_users where playername='$player'";
    $userstats2=mysql_query($userstats) or die("Could not get user stats");
    $userstats3=mysql_fetch_array($userstats2);

$atk1=$userstats3['atkskill']+$userstats3['defend'];
echo "$userstats3[playername]<br>";
echo "$userstats3[atkskill]<br>";
echo "$userstats3[defend]<br>";
echo "$atk1<br>";


$playertwo="SELECT * from ac_users where ID='$playerID'";
$playertwo2=mysql_query($playertwo) or die("Blah");
$playertwo3=mysql_fetch_array($playertwo2);




$atk2=$playertwo3['atkskill']+$playertwo3['defend'];
echo "$playertwo3[playername]<br>";
echo "$playertwo3[atkskill]<br>";
echo "$playertwo3[defend]<br>";
echo "$atk2<br>";

echo "<center><font color=#FFFFF><u>Player Challenge</u><P>";

if($userstats3['numturns']<50)
{
print "<center><font color=#FFFFF face=Verdana size=1>You need 50 turns to fight a player<a href=index.php> Back</a>";
}
else if ($playertwo3)
{
print "<center><font color=#FFFFF face=Verdana size=1>No such user<a href=index.php> Back</a>";
}
else
{

$update=$userstats3['atkskill']/10;
$update2=$playertwo3['atkskill']/10;

if($atk1>$atk2)
{
echo "<center><font color=#FFFFF face=Verdana size=1>You Won<P> Gained $update Skillpts<P><a href='index.php'>Back</a>";

$skill="update ac_users set atkskill=atkskill+'$update', numturns=numturns-'50' where playername='$player'";
mysql_query($skill);

}
else
if($atk2>$atk1)
{
echo "<center><font color=#FFFFF face=Verdana size=1>You Lose";

$skill2="update ac_users set atkskill=atkskill+'$update2' where ID='$playertwo3[ID]'";
mysql_query($skill2);

}
}
}
else
{
print "Nope";
}
?>
[/color]

And mind you I'm attack from a link. And not box with a button if that matters at all. Any help would be greatly appreciated.
Link to comment
Share on other sites

Ok.. in the link used to access this script you pasted, how is the player being attacked specified?  Can you post an example of one of the links?  Then we can show you how to use that id to fetch the player's data from the database.

I would expect something like http://domain.com/script.php?playerID=5
Link to comment
Share on other sites

Thanks!  Then what is missing from your code is this:

[code]if (!isset($_GET['ID'])) {
  print "No player was selected to attack.<br>";
} else {
  $playerID = $_GET['ID'];
}[/code]

That code needs to go before you use $playerID to select data from the database.
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.