Hello,

I was working on a small project to make me think, and I ran across a problem when I was running a page. Instead of any error coming up, the page just produced the following, which was part of my code:

0 && $user_health > 0) { $monster_health = find_enemy_health($_SESSION['user_id'], $monster_id, $weapon_equipped, $user_health, $monster_health); if ($monster_health > 0) { $user_health = find_user_battle_health($_SESSION['user_id'], $monster_id, $armor_equipped, $user_health); } } if ($monster_health < 1 && $user_health > 0) { $monster_exp = find_monster_exp($monster_id); $user_exp = find_user_exp($user_id); $user_exp = $user_exp + $monster_exp; $success = update_user_exp($_SESSION['user_id'], $user_exp); $success2 = update_user_health($_SESSION['user_id'], $user_health); $total_success = $success + $success2; if ($total_success == 2) { $battle = battle_success($_SESSION['user_id'], $monster_id); } } else if ($user_health < 1) { $success = user_death($_SESSION['user_id'], $monster_id); } ?>

I'm not actually looking for an actual answer, but I don't know what kind of error this is, and why it happens, so that I might try to fix it myself.

If I need to, I can post the surrounding code, but I would like to try to solve it myself

Recommended Answers

All 6 Replies

Somehow, there must be an open quote from an echo statement just before all of that or just a typo before that 0 which appears to be part of an if statement..

I looked for open quotes, and I couldn't find any. Also, that conditional is in a while loop. I don't know if that is correct syntax to have a and operator so could that cause the problem?

while loops could be better named "wild loops" as it is very easy to get unpredictable results from them. I try to avoid them, but that's just my opinion.
I think multiple conditions are OK if the entire inner expression is contained in parenthesis.

while (($a > 0 && $b > 0))
{
//do stuff
}

Hmm...I tried that, and it didn't work again.
I think that I may go with your advice about avoiding while loops, and try some longer, safer(?) code.

I'll come back when I get some results

while loops could be better named "wild loops" as it is very easy to get unpredictable results from them. I try to avoid them, but that's just my opinion.
I think multiple conditions are OK if the entire inner expression is contained in parenthesis.

while (($a > 0 && $b > 0))
{
//do stuff
}

One last thought...add more parenthesis!

while ((($a > 0) && ($b > 0))) //each condition and the entire expression get "()"
{
//do stuff
}

Otherwise, yeah, PLAN B.

I made a stupid mistake nowhere near the while loop, but I've fixed it now, thanks!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.