I'm trying to build a mortgage qualifying script for a company. My php code is working fine .. up until the if else statements. fyi I'm using wamp... heres the code. The code if very raw, i've only been working on it for a day or 2, but I can't understand why my if else statements aren't working.

index.htm

<html>

<body>
<h1>Lead Capture</h1>
<div id = "leadcapture">
             <form method="post" action="process.php"> 
              Name:<br> <input name="name" type="text" STYLE="background: white; border: 1px #CACACA solid;"><br >

              Phone:<br><input name="phone" maxlength="13" size="13" type="text" STYLE="background: white; border: 1px #CACACA solid;"><br >

              Email: <br><input name="email" type="text" STYLE="background: white; border: 1px #CACACA solid;"><br >

              Market Value or Purchase Price of Property:<br ><input name="value" type="text" maxlength="9" size="10" STYLE="background: white; border: 1px #CACACA solid;"><br >

	<b><u>Loan Amount:</b></u><br>
	Purchase: Loan amount after down payment.<br>
	Refinance: Payoff.<br>
	Refinance (Cashout): Payoff + cash requesting.<br><input name="payoff" maxlength="9" size="10" type="text" STYLE="background: white; border: 1px #CACACA solid;"><br >

	Current Interest Rate(if applicable):<br ><input name="rate" type="text" maxlength="5" size="5" STYLE="background: white; border: 1px #CACACA solid;"><br >
	
	Estimated Credit Score: <br><select name="credit">
		<option value=">740">>740</option>
		<option value="739-720">739-720</option>
		<option value="719-700">719-700</option>
		<option value="699-680">699-680</option>
		<option value="679-660">679-660</option>
		<option value="659-640">659-640</option>
		<option value="639-600">639-600</option>
		<option value="<600"><600</option>
		</select><br>
	
	Refinance or Buy:<br><select name="buysell">
		<option value="buy">Buy</option>
		<option value="refinance">Refinance</option>
		<option value="cashout">Refinance-Cashout</option>		
		</select><br>



	<input type="submit" name="go" value="submit"> 
	
	</form>
</div>
</body>
</html>

process.php

<?php
$name=$_POST['name'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$payoff=$_POST['payoff'];
$value=$_POST['value'];
$rate=$_POST['rate'];
$credit=$_POST['credit'];
$buysell=$_POST['buysell'];

$number=($payoff/$value)*100;

echo "Name:  $name<br>";
echo "Phone: $phone<br>";
echo "Email: $email<br>";
echo "Payoff: $payoff<br>";
echo "Market Value: $value<br>";
echo "Current Interest Rate:  $rate<br>";
echo "Estimated Credit Score: $credit<br>";
echo "You want to $buysell a property<br><br>";

echo"$number %<br>";

if($buysell=="Refinance - Cashout"){
	if($number >= 96.5){
		echo "Your Loan to Value Ratio is too high to Receive any cash out or to  refinance ";
	}elseif($number < 96.5 && $number > 80 ) { 
		echo "Your Loan to Value Ration is too high to receive any cash out but you are still able to refinance your property.";
	}else{
		echo "Prior to any closing costs being subtracted your estimated cash back is $cashback.";
	}
}
?>

Dani AI

Generated

As noted, the immediate cause is a mismatch between the select option value sent by the form and the exact string the PHP conditional checks. PHP string comparisons are exact (and by default case-sensitive), so if the HTML sends a short token but the script expects a longer label the if branch will never run. Use stable, machine-readable value attributes in the <option>s (e.g., cashout, refinance) and compare against those, or change the option values to match the script.

Also harden the numeric logic and add basic validation so the LTV check behaves predictably. Strip commas/currency characters, cast to floats, and guard against division by zero before comparing percentages:

$payoff = floatval(preg_replace('/[^\d\.]/', '', $_POST['payoff'] ?? '0'));
$value  = floatval(preg_replace('/[^\d\.]/', '', $_POST['value']  ?? '0'));

if ($value <= 0) {
    echo "Please enter a valid market value.";
    exit;
}
$ltv = ($payoff / $value) * 100;

Quick debugging tips: dump the submitted data with var_dump($_POST) and enable errors (error_reporting(E_ALL); ini_set('display_errors',1);) to confirm exactly what the form sends. Check the name attributes too — inconsistent names cause empty values. In the HTML posted, some <option> value attributes contain characters like < and > or visible labels that differ from values; simplify those to plain tokens to avoid surprises.

Final notes: normalize comparisons with trim()/strtolower() or use strict equality checks once values are standardized, format numbers for output with number_format(), and prefer HTML5 type="number" for numeric inputs to reduce bad input. Good catch by , once the values match and inputs are sanitized the if/else branches will behave as expected.

<option value="cashout">Refinance-Cashout</option>
$buysell=="Refinance - Cashout"

That doesn't match.
Should be

$buysell=="cashout"
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.