PHP and HTML formatting tags -- What am I doing wrong?

I have a form on an HTML file where the user can input their total debt (textbox named “totdebt”) and their total income (textbox named “income”). When they hit Send they’re supposed to get their credit evaluated.

It seems that something in my code (I think it’s the < and > from my various html formatting tags) is messing up the php script. It boggles me because I just did another php script last week and it worked without a hitch–it had several formatting tags too.


<html>
<head><title>Credit Application</title></head>
<body>

<h2>Credit Approval Form</h2>

<?php
   $debtincome = $totdebt / $income;
   $income15 = $income * 0.15;
   $income30 = $income * 0.30;

   print ("Total Debt is $totdebt<br>");
   print ("Total Income is $income<br>");
   print ("Amount of Debt as percentage of Total Income is $debtincome<p>");

   if ($totdebt < $income15) {
      print ("<font color=green size=4>Credit is approved.</font>");
   } elseif ($totdebt >= $income15 && $totdebt <= $income30) {
      print ("<font color=blue size=4>Credit is borderline.</font>");
   } elseif ($totdebt > $income30) {
      print ("<font color=red size=4>Credit is NOT APPROVED.</font>");
   }
?>
</body>
</html>

When I put this through Firefox, the first three “print” lines don’t show up. View Source reveals to me that the browser thinks the php script ends after the first <br> (after “Total Debt is $totdebt”).

I’d Google this if I could. :confused:

I believe your print statements need single quotes (’) instead of doubles (") – the doubles are interpreted by PHP as “post-process whatever’s in this string”, whereas the singles are “just take this string as-is, without processing”.

I had already tried that, and I just tried it again now. Same problem. :confused:

I just copied your script into a php file on my system and it works fine. Of course, since I didn’t have your form that calls this page, I had to add two lines to the beginning of the script:

$totdebt = 1000;
$income = 900;

Are you sure these variables are being set properly?
Try writing a script to just print the contents of these two variables,
to make sure the values are coming through ok.

What version of PHP are you using? If you’re not sure,
add the following to the end of your html file, then view it:

<?php
phpinfo ();
?>

I’m running PHP 4.3.9.

Would you mind if I PMed you a link to what I have up?

Sure, go ahead…

You don’t have your emails enabled so I guess I’ll just post a URL here then:
http://x.elusivestar.com/testing

Ah, sorry about that. When you said you’d PM I thought you meant through Yahoo :wink:

I see the error that you’re talking about. When I did a ‘view source’ on the output page, I could see the entire PHP script, which means the preprocessor isn’t handling it for some reason. I originally was thinking it was a problem with your system configuration, but I downloaded your files to my system and it does the same thing.

Oddly, the file that I typed in using the script I copied from the forum works fine. Your output.php file may be corrupt. Try creating a NEW file, and copy the following into it. It should work for you (it does for me). Of course, remove the hardcoded values once you see it work…

<html>
<head><title>Credit Application</title></head>
<body>

<h2>Credit Approval Form</h2>

<?php
$totdebt = 1000;
$income = 900;
$debtincome = $totdebt / $income;
$income15 = $income * 0.15;
$income30 = $income * 0.30;

print (“Total Debt is $totdebt<br>”);
print (“Total Income is $income<br>”);
print (“Amount of Debt as percentage of Total Income is $debtincome<p>”);

if ($totdebt < $income15) {
print ("<font color=green size=4>Credit is approved.</font>");
} elseif ($totdebt >= $income15 && $totdebt <= $income30) {
print ("<font color=blue size=4>Credit is borderline.</font>");
} elseif ($totdebt > $income30) {
print ("<font color=red size=4>Credit is NOT APPROVED.</font>");
}
?>
<?php
phpinfo ();
?>
</body>

I just created a new file with what I posted in my OP and you’re right–it works. I’m not even going to tell you how much time I wasted re-editing the same corrupt file. :smack:

Thank you so much. Your help is very much appreciated. :slight_smile: :slight_smile:

I examined your output.php file with a binary editor and it appears to be unicode. I don’t think the PHP preprocessor can handle a unicode file correctly, at least not in version 4. No doubt someone will correct me if I’m wrong.

Recreating the file–as I mentioned in the previous post–with a more standard text file format might fix your problem.

Simulpost!

I’m glad it works…happy coding!