seany123 Posted September 28, 2008 Share Posted September 28, 2008 im getting this error: Parse error: parse error, unexpected T_VARIABLE in xxxx/xxxx/xxxxxxx on line 27. This is the code. <? include ("lib.php"); if ($_GET['act'] == "1" && $player->nerve > 0) { if($perc2 > 74 && $crime < 9) { if (25 + $player->exp >= $player->maxexp) //Player gained a level! { //Update player echo "You gained 25 EXP and $10"; $query = $db->execute("update `players` set `exp`=?, `money`=?, `nerve`=? where `id`=?", array($player->exp + 25, $player->money + 10, $player->nerve - 1, $player->id)); } } else if($crime > 8 && $jail < 3) { //Update player echo "You Failed the Crime and was sent to Prison!"; $query = $db->execute("update `players` set `nerve`=?, `prison`=? where `id`=?", array($player->nerve - 1, $player->prison + 1, $player->id)); } else if($crime > { //Update player echo "You Failed the Crime!"; $query = $db->execute("update `players` set `nerve`=? where `id`=?", array($player->nerve - 1, $player->id)); } else { if($perc2 > 48 && $perc2 < 75 $crime < 7) { if (25 + $player->exp >= $player->maxexp) //Player gained a level! { //Update player, gained a level echo "You gained 25 EXP" $query = $db->execute("update `players` set `points`=?, `level`=?, `maxexp`=?, `maxhp`=?, `exp`=?, `money`=?, `hp`=?, `nerve`=? where `id`=?", array($player->points + 3, $player->level + 1, ($player->level+1) * 70 - 20, $player->maxhp + 30, $player->money + 10, $newexp, $player->nerve - 1, $player->id)); } else //Update player echo "You gained 25 EXP" $query = $db->execute("update `players` set `exp`=?, `nerve`=? where `id`=?", array($player->exp + 25, $player->nerve - 1, $player->id)); } } else if($crime > 6 && $jail < 3) { //Update player echo "You Failed the Crime and was sent to Prison!"; $query = $db->execute("update `players` set `nerve`=?, `prison`=? where `id`=?", array($player->nerve - 1, $player->prison + 1 $player->id)); } else if($crime > 6) { //Update player echo "You Failed the Crime!"; $query = $db->execute("update `players` set `nerve`=? where `id`=?", array($player->nerve - 1, $player->id)); } else { if($perc2 > 24 && $perc2 < 49 && $crime < 5) { if (25 + $player->exp >= $player->maxexp) //Player gained a level! { //Update player, gained a level echo "You gained 25 EXP" $query = $db->execute("update `players` set `points`=?, `level`=?, `maxexp`=?, `maxhp`=?, `exp`=?, `money`=?, `hp`=?, `nerve`=? where `id`=?", array($player->points + 3, $player->level + 1, ($player->level+1) * 70 - 20, $player->maxhp + 30, $player->money + 10, $newexp, $player->nerve - 1, $player->id)); } else //Update player echo "You gained 25 EXP" $query = $db->execute("update `players` set `exp`=?, `nerve`=? where `id`=?", array($player->exp + 25, $player->nerve - 1, $player->id)); } } else if($crime > 4 && $jail < 3) { //Update player echo "You Failed the Crime and was sent to Prison!"; $query = $db->execute("update `players` set `nerve`=?, `prison`=? where `id`=?", array($player->nerve - 1, $player->prison + 1 $player->id)); } else if($crime > 4) { //Update player echo "You Failed the Crime!"; $query = $db->execute("update `players` set `nerve`=? where `id`=?", array($player->nerve - 1, $player->id)); } else { if($perc2 > 0 && $perc2 < 25 && $crime < 3) { if (25 + $player->exp >= $player->maxexp) //Player gained a level! { //Update player, gained a level echo "You gained 25 EXP" $query = $db->execute("update `players` set `points`=?, `level`=?, `maxexp`=?, `maxhp`=?, `exp`=?, `money`=?, `hp`=?, `nerve`=? where `id`=?", array($player->points + 3, $player->level + 1, ($player->level+1) * 70 - 20, $player->maxhp + 30, $player->money + 10, $newexp, $player->nerve - 1, $player->id)); } else //Update player echo "You gained 25 EXP" $query = $db->execute("update `players` set `exp`=?, `nerve`=? where `id`=?", array($player->exp + 25, $player->nerve - 1, $player->id)); } } else if($crime > 2 && $jail < 3) { //Update player echo = "You Failed the Crime and was sent to Prison!"; $query = $db->execute("update `players` set `nerve`=?, `prison`=? where `id`=?", array($player->nerve - 1, $player->prison + 1 $player->id)); } else if($crime > 2) { //Update player echo "You Failed the Crime!"; $query = $db->execute("update `players` set `nerve`=? where `id`=?", array($player->nerve - 1, $player->id)); } else { echo "Not enough Nerve"; } ?> whats wrong with the code? Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/ Share on other sites More sharing options...
ratcateme Posted September 28, 2008 Share Posted September 28, 2008 look at the join between the second and third part of the if on line 29 of the code you posted. you missed a ; off the next to echos. and on line 43 you are trying to "else if" and block that has already been else'ed Scot. Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/#findComment-652159 Share on other sites More sharing options...
seany123 Posted September 28, 2008 Author Share Posted September 28, 2008 how do you mean by: and on line 43 you are trying to "else if" and block that has already been else'ed how do i fix this? Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/#findComment-652319 Share on other sites More sharing options...
seany123 Posted September 28, 2008 Author Share Posted September 28, 2008 can someone help me with this please? Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/#findComment-652344 Share on other sites More sharing options...
.josh Posted September 28, 2008 Share Posted September 28, 2008 else //Update player echo "You gained 25 EXP" You don't have a { after else and you forgot a ; Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/#findComment-652346 Share on other sites More sharing options...
ratcateme Posted September 28, 2008 Share Posted September 28, 2008 i am not exactly sure but you are missing a lot of {'s and }'s that make your code very hard to read and i am fairly sure they are making it not work properly Scott. Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/#findComment-652430 Share on other sites More sharing options...
seany123 Posted September 28, 2008 Author Share Posted September 28, 2008 I can see that maybe there too much in the code for you to really see any errors, so i have stripped the code down completely: <? if ($_GET['act'] == "1" && $player->nerve > 0) { if($perc2 > 74 && $crime < 9) { } else if($crime > 8 && $jail < 3) { } else if($crime > { } else { if($perc2 > 48 && $perc2 < 75 $crime < 7) { } else if($crime > 6 && $jail < 3) { } else if($crime > 6) { } else { if($perc2 > 24 && $perc2 < 49 && $crime < 5) { } else if($crime > 4 && $jail < 3) { } else if($crime > 4) { } else { if($perc2 > 0 && $perc2 < 25 && $crime < 3) { } else if($crime > 2 && $jail < 3) { } else if($crime > 2) { } } else { echo "Not enough Nerve"; } ?> still getting same T_VARIABLE error on line 18. Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/#findComment-652482 Share on other sites More sharing options...
.josh Posted September 28, 2008 Share Posted September 28, 2008 great thing about indenting is it's easier to tell when things go awry. Assuming this is how you really want your conditions structured: <? if ($_GET['act'] == "1" && $player->nerve > 0){ if($perc2 > 74 && $crime < 9){ } else if($crime > 8 && $jail < 3) { } else if($crime > { } else { if($perc2 > 48 && $perc2 < 75 $crime < 7) { } else if($crime > 6 && $jail < 3) { } else if($crime > 6) { } else { if($perc2 > 24 && $perc2 < 49 && $crime < 5) { } else if($crime > 4 && $jail < 3){ } else if($crime > 4) { } else { if($perc2 > 0 && $perc2 < 25 && $crime < 3) { } else if($crime > 2 && $jail < 3) { } else if($crime > 2) { } // problem starts here } else { echo "Not enough Nerve"; } ?> You know I'm actually looking at the conditions themselves and I strongly advise you sit down and rethink what it is you're trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/#findComment-652489 Share on other sites More sharing options...
seany123 Posted September 28, 2008 Author Share Posted September 28, 2008 same error Parse error: parse error, unexpected T_VARIABLE on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/#findComment-652499 Share on other sites More sharing options...
wildteen88 Posted September 28, 2008 Share Posted September 28, 2008 I don't think CV actually fixed your code, but give an example of how clear your code becomes when you indent. Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/#findComment-652517 Share on other sites More sharing options...
seany123 Posted September 28, 2008 Author Share Posted September 28, 2008 oh right. well to be honest, i know its easier to read, but other than that there is no other reason for me to indent my codes. yeah i am lazy but i get through a lot of codes and it isn't really worth keeping having to make it look good. Can anyone help me with why im getting this error? Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/#findComment-652568 Share on other sites More sharing options...
CroNiX Posted September 28, 2008 Share Posted September 28, 2008 If you indented your code you wouldn't be having this problem because you could see it visibly. Guess its just easier to have other people try to fix it for you though. Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/#findComment-652582 Share on other sites More sharing options...
CroNiX Posted September 28, 2008 Share Posted September 28, 2008 And actually, CV did point out exactly where the problem is if you took the time to look. HINT: else...else Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/#findComment-652583 Share on other sites More sharing options...
seany123 Posted September 28, 2008 Author Share Posted September 28, 2008 i already fixed the { and ; Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/#findComment-652585 Share on other sites More sharing options...
CroNiX Posted September 28, 2008 Share Posted September 28, 2008 You have: <?php else { if(blah){ //blah elseif(blah){ //blah } } else { //blah } 2 elses next to each other when it should be elseif...else Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/#findComment-652594 Share on other sites More sharing options...
ratcateme Posted September 29, 2008 Share Posted September 29, 2008 did you look at the line in the error? did you check the line in the error if($perc2 > 48 && $perc2 < 75 $crime < 7) { needs to be if($perc2 > 48 && $perc2 < 75 && $crime < 7) { Scott. Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/#findComment-652635 Share on other sites More sharing options...
seany123 Posted September 29, 2008 Author Share Posted September 29, 2008 yes fixed the &&. getting T_ELSE error on line 29. <? include ("lib.php"); if ($_GET['act'] == "1" && $player->nerve > 0) { if($perc2 > 74 && $crime < 9) { if (25 + $player->exp >= $player->maxexp) //Player gained a level! { //Update player echo "You gained 25 EXP and $10"; $query = $db->execute("update `players` set `exp`=?, `money`=?, `nerve`=? where `id`=?", array($player->exp + 25, $player->money + 10, $player->nerve - 1, $player->id)); } } else if($crime > 8 && $jail < 3) { //Update player echo "You Failed the Crime and was sent to Prison!"; $query = $db->execute("update `players` set `nerve`=?, `prison`=? where `id`=?", array($player->nerve - 1, $player->prison + 1, $player->id)); } else if($crime > { //Update player echo "You Failed the Crime!"; $query = $db->execute("update `players` set `nerve`=? where `id`=?", array($player->nerve - 1, $player->id)); } else { else if($perc2 > 48 && $perc2 < 75 || $crime < 7) { if (25 + $player->exp >= $player->maxexp) //Player gained a level! { //Update player, gained a level echo "You gained 25 EXP" $query = $db->execute("update `players` set `points`=?, `level`=?, `maxexp`=?, `maxhp`=?, `exp`=?, `money`=?, `hp`=?, `nerve`=? where `id`=?", array($player->points + 3, $player->level + 1, ($player->level+1) * 70 - 20, $player->maxhp + 30, $player->money + 10, $newexp, $player->nerve - 1, $player->id)); } else //Update player echo "You gained 25 EXP" $query = $db->execute("update `players` set `exp`=?, `nerve`=? where `id`=?", array($player->exp + 25, $player->nerve - 1, $player->id)); } } else if($crime > 6 && $jail < 3) { //Update player echo "You Failed the Crime and was sent to Prison!"; $query = $db->execute("update `players` set `nerve`=?, `prison`=? where `id`=?", array($player->nerve - 1, $player->prison + 1 $player->id)); } else if($crime > 6) { //Update player echo "You Failed the Crime!"; $query = $db->execute("update `players` set `nerve`=? where `id`=?", array($player->nerve - 1, $player->id)); } else { if($perc2 > 24 && $perc2 < 49 || $crime < 5) { if (25 + $player->exp >= $player->maxexp) //Player gained a level! { //Update player, gained a level echo "You gained 25 EXP" $query = $db->execute("update `players` set `points`=?, `level`=?, `maxexp`=?, `maxhp`=?, `exp`=?, `money`=?, `hp`=?, `nerve`=? where `id`=?", array($player->points + 3, $player->level + 1, ($player->level+1) * 70 - 20, $player->maxhp + 30, $player->money + 10, $newexp, $player->nerve - 1, $player->id)); } else //Update player echo "You gained 25 EXP" $query = $db->execute("update `players` set `exp`=?, `nerve`=? where `id`=?", array($player->exp + 25, $player->nerve - 1, $player->id)); } } else if($crime > 4 && $jail < 3) { //Update player echo "You Failed the Crime and was sent to Prison!"; $query = $db->execute("update `players` set `nerve`=?, `prison`=? where `id`=?", array($player->nerve - 1, $player->prison + 1 $player->id)); } else if($crime > 4) { //Update player echo "You Failed the Crime!"; $query = $db->execute("update `players` set `nerve`=? where `id`=?", array($player->nerve - 1, $player->id)); } else { if($perc2 > 0 && $perc2 < 25 || $crime < 3) { if (25 + $player->exp >= $player->maxexp) //Player gained a level! { //Update player, gained a level echo "You gained 25 EXP" $query = $db->execute("update `players` set `points`=?, `level`=?, `maxexp`=?, `maxhp`=?, `exp`=?, `money`=?, `hp`=?, `nerve`=? where `id`=?", array($player->points + 3, $player->level + 1, ($player->level+1) * 70 - 20, $player->maxhp + 30, $player->money + 10, $newexp, $player->nerve - 1, $player->id)); } else //Update player echo "You gained 25 EXP" $query = $db->execute("update `players` set `exp`=?, `nerve`=? where `id`=?", array($player->exp + 25, $player->nerve - 1, $player->id)); } } else if($crime > 2 && $jail < 3) { //Update player echo = "You Failed the Crime and was sent to Prison!"; $query = $db->execute("update `players` set `nerve`=?, `prison`=? where `id`=?", array($player->nerve - 1, $player->prison + 1 $player->id)); } else if($crime > 2) { //Update player echo "You Failed the Crime!"; $query = $db->execute("update `players` set `nerve`=? where `id`=?", array($player->nerve - 1, $player->id)); } else { echo "Not enough Nerve"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/#findComment-653148 Share on other sites More sharing options...
seany123 Posted September 29, 2008 Author Share Posted September 29, 2008 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/#findComment-653265 Share on other sites More sharing options...
.josh Posted September 29, 2008 Share Posted September 29, 2008 Dude, the answers have already been given to you, several times. Go back and look at the posted codes, from any number of people. You get one thing fixed and the same exact error shows up a few lines later. What does that tell you? Because posting the same error for a few lines down just tells us you're too lazy to read what's being posted or fix it yourself. Quote Link to comment https://forums.phpfreaks.com/topic/126119-getting-t_variable-error/#findComment-653280 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.