SoireeExtreme Posted November 9, 2006 Share Posted November 9, 2006 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);}elseif($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] Quote Link to comment Share on other sites More sharing options...
btherl Posted November 9, 2006 Share Posted November 9, 2006 Try displaying the values of $atk1, $atk2 and everything they depend on ($userstats3['atkskill'] and so on). You'll probably notice something odd. It's the ideal method for debugging this kind of problem. Quote Link to comment Share on other sites More sharing options...
SoireeExtreme Posted November 9, 2006 Author Share Posted November 9, 2006 Thanks that would as good idea. I shows that it is not getting atk2 of playertwo.So now my question would be. How do I get it to register and get atk2 of playertwo?I'll try to figure it out in the mean time and post back if I get it working. Thanks. Quote Link to comment Share on other sites More sharing options...
btherl Posted November 9, 2006 Share Posted November 9, 2006 Next, print out the values that $atk2 was set from.. and if they are not what you expect, print out the values those values were set from :)Once you get back far enough, you'll find the problem. It may just be a typo. Quote Link to comment Share on other sites More sharing options...
SoireeExtreme Posted November 9, 2006 Author Share Posted November 9, 2006 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. Quote Link to comment Share on other sites More sharing options...
btherl Posted November 9, 2006 Share Posted November 9, 2006 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. Quote Link to comment Share on other sites More sharing options...
SoireeExtreme Posted November 9, 2006 Author Share Posted November 9, 2006 Thanks for trying to help me. But being as new as I am at this point I don't understand. Oh well guess I'm at a lost. Thanks again. Quote Link to comment Share on other sites More sharing options...
btherl Posted November 9, 2006 Share Posted November 9, 2006 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 :) Quote Link to comment Share on other sites More sharing options...
SoireeExtreme Posted November 9, 2006 Author Share Posted November 9, 2006 Here is the script.[color=maroon]<?phpif (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);}elseif($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. Quote Link to comment Share on other sites More sharing options...
btherl Posted November 9, 2006 Share Posted November 9, 2006 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 Quote Link to comment Share on other sites More sharing options...
SoireeExtreme Posted November 9, 2006 Author Share Posted November 9, 2006 <TD> <A href='attack.php?ID=$userselect3[ID]'>Attack</a>Would be where the attack is coming from. Quote Link to comment Share on other sites More sharing options...
btherl Posted November 9, 2006 Share Posted November 9, 2006 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. Quote Link to comment Share on other sites More sharing options...
SoireeExtreme Posted November 9, 2006 Author Share Posted November 9, 2006 No Thank you. Thank you very much. Just ran into a a couple other problems. But I think I can handle those. If not I'll be back. lol... Thanks a million. I'm sure I won't be the only person happy and wanting to thank you... lol. 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.