kingdkknox Posted June 16, 2010 Share Posted June 16, 2010 Okay yall gonna laugh at me but Im trying... I try to add where my users have to have a certain amount of stats before they can get exp. points to prevent people from getting super high levels wit no stats. I get an error that I have an unexpected else. Any way this is what I did this what was there. if($odata['hp'] <= 0){$odata['hp']=0;$_SESSION['attackwon']=$_GET['ID'];$db->query("UPDATE users SET hp=0 WHERE userid={$_GET['ID']}");print " [b]What do you want to do with {$odata['username']} now?[/b] <form action='attackwon.php?ID={$_GET['ID']}' method='post'><input type='submit' STYLE='color: white; background-color: red;' value='Mug Them' /> </form> <form action='attackbeat.php?ID={$_GET['ID']}' method='post'><input type='submit' STYLE='color: white; background-color: green;' value='Hospitalize Them' /> </form> <form action='attacktake.php?ID={$_GET['ID']}' method='post'><input type='submit' STYLE='color: black; background-color: white;' value='Leave Them' /> </form> NB:If you not choose any of the option above you lose all your EXP point ! If you and the enemy beaten are on the same battle ladder mug them to get points added to the ladder table ! "; right after that I added }else if ($odata['hp'] <= 0 and ($youdata['strength']+$youdata['guard']+$youdata['agility']) < ($youdata['level']*60000));{$odata['hp']=0;$_SESSION['attackwon']=$_GET['ID'];$db->query("UPDATE users SET hp=0 WHERE userid={$_GET['ID']}");print " [b]What do you want to do with {$odata['username']} now?[/b] <form action='attackwon.php?ID={$_GET['ID']}' method='post'><input type='submit' STYLE='color: white; background-color: red;' value='Mug Them' /> </form> <form action='attackbeat.php?ID={$_GET['ID']}' method='post'><input type='submit' STYLE='color: white; background-color: green;' value='Hospitalize Them' /> </form> Before you can get anymore exp. you have to work on your stats.NB:If you not choose any of the option above you lose all your EXP point ! If you and the enemy beaten are on the same battle ladder mug them to get points added to the ladder table ! ";} This is the line where the error is I just posted the whole thing. unexpected else else {//choose opp gun$eq=$db->query("SELECT i.* FROM items i WHERE i.itmid IN({$odata['equip_primary']}, {$odata['equip_secondary']})");if(mysql_num_rows($eq) == 0){$wep="Fists";$dam=(int)((((int) ($odata['strength']/$ir['guard']/100)) +1)*(rand(8000,12000)/10000));}else{$cnt=0;while($r=$db->fetch_row($eq)){$enweps[]=$r;$cnt++;}$weptouse=rand(0,$cnt-1);$wep=$enweps[$weptouse]['itmname'];$dam=(int) (($enweps[$weptouse]['weapon']*$odata['strength']/($youdata['guard']/1.5))*(rand(8000,12000)/10000));}$hitratio=max(10,min(60*$odata['agility']/$ir['agility'],95));if(rand(1,100) <= $hitratio) If anyone has better way to do this that would be great also.... Quote Link to comment Share on other sites More sharing options...
DougK Posted June 17, 2010 Share Posted June 17, 2010 YUCK! First of all, I would suggest making better use of whitespace. Cramming everything together does NOT make it run any faster. Here is a copy of your first snippet with additional whitespace: if($odata['hp'] <= 0) { $odata['hp']=0;$_SESSION['attackwon']=$_GET['ID']; $db->query("UPDATE users SET hp=0 WHERE userid={$_GET['ID']}"); print " [b]What do you want to do with {$odata['username']} now?[/b] <form action='attackwon.php?ID={$_GET['ID']}' method='post'> <input type='submit' STYLE='color: white; background-color: red;' value='Mug Them' /></form> <form action='attackbeat.php?ID={$_GET['ID']}' method='post'> <input type='submit' STYLE='color: white; background-color: green;' value='Hospitalize Them' /></form> <form action='attacktake.php?ID={$_GET['ID']}' method='post'> <input type='submit' STYLE='color: black; background-color: white;' value='Leave Them' /> </form> NB:If you not choose any of the option above you lose all your EXP point ! If you and the enemy beaten are on the same battle ladder mug them to get points added to the ladder table !"; See how much easier that is to read? Now, on to the actual problem. You have a semicolon after your second else }else if ($odata['hp'] <= 0 and ($youdata['strength']+$youdata['guard']+$youdata['agility']) < ($youdata['level']*60000)); <== Here is your problem Get that out of there. PHP does accept inline conditionals, so you could have if ( $var == 1) print "$var is one."; or if ($var == 1) { print "$var is one." } and both are valid. Quote Link to comment Share on other sites More sharing options...
kingdkknox Posted June 17, 2010 Author Share Posted June 17, 2010 Thanks bro! And Im glad you didnt get aggy wit me like most people do. Thanks for your help! Quote Link to comment Share on other sites More sharing options...
Joshua Posted June 17, 2010 Share Posted June 17, 2010 Not everyone on this board will get agg'd with you :) We all started somewhere (: Quote Link to comment Share on other sites More sharing options...
DougK Posted June 17, 2010 Share Posted June 17, 2010 This is a site for sharing knowledge, though I will admit there are some that seem to lord what they know over those who are still learning. Everyone has to start somewhere. Semicolons can be killer. I don't feel ashamed admitting it, but I sometimes make the same mistake, though forgetting a semicolon or using a directive that is used by the proprietary code of my company's software. FYI, by adding whitespace, that error became readily apparent. Glad to help Quote Link to comment Share on other sites More sharing options...
Joshua Posted June 17, 2010 Share Posted June 17, 2010 My biggest problem is missing a ' or ` sometimes in a statement, query or echo type statement be amazed how hard that key is to hit sometimes it would seem i.e mysql_query("SELECT `userid` FROM `users` WHERE `userid !=".$r['userid'].""); The above code would error and depending on how late it is I could stare at it forever and just NOT see it >,< I end up looking above and below that line to figure it out, especially if it's not a query and doesnt say "query error" lol i.e echo "blah blah'; can't count the number of times i've done that >< Quote Link to comment Share on other sites More sharing options...
Spudinski Posted June 17, 2010 Share Posted June 17, 2010 One of your examples are incorrect. A semicolon signifies the end of a PHP statement, so your last example would not work(yes, I have tested it myself). Please correct it. Quote Link to comment Share on other sites More sharing options...
Joshua Posted June 17, 2010 Share Posted June 17, 2010 A semicolon also signifies the end of a database query it's not "incorrect" The reason the above statement won't work is because i'm missing a ` (Intentional) Neither of the above should work i was demonstrating a common error i make. The 2nd example you are reffering to however was assuming the echo is between { } tags from an if statement, i'm just being lazy It was an example of a common typo i do when I get in a hurry. lol. jeez Quote Link to comment Share on other sites More sharing options...
Spudinski Posted June 17, 2010 Share Posted June 17, 2010 DougK's post. Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted June 17, 2010 Share Posted June 17, 2010 What i don't understand is why this is in non-mccode support but in fact it's mcc... 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.