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

Dani AI

Generated

When PHP source appears verbatim in the browser the server did not execute the PHP interpreter for that request. Syntax mistakes can cause many kinds of headaches (as pointed out) and eventually fixed the issue, but raw code in the page usually means the file was served as plain text or the interpreter never ran — not a PHP runtime error shown by the engine.

Quick checklist to reproduce and diagnose:

Create a minimal test file and load it in the same location as the failing page to confirm whether PHP is being parsed:

<?php phpinfo(); ?>

If you see the phpinfo() page, PHP is running and the problem is in the specific file or include chain. If you see the literal code, check these common causes: correct .php extension, using full <?php tags (see the PHP tags documentation), the short_open_tag setting (if using short tags) and whether the server is configured to hand .php files to PHP. Also watch for an invisible BOM at the top of a file; it can force output before PHP runs. The phpinfo() reference helps confirm server-level settings.

If diagnostics show PHP running, use php -l filename.php to lint the file and check webserver error logs for include/handler issues. Keep edits minimal and test a small, standalone file to isolate the fault.

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.