View Full Version : Undefined Index Warning

06-10-2007, 03:05 PM

I'm running a script which is resulting with one variable as an Undefined Index. The error message is:
Undefined index: intcredit in C:\Inetpub\fullfocus\AtlantaMtgPlace\loan_options.php on line 23

I do not understand why this message is appearing. The form which contains the answer to this question is a radio button. I have two additional radio button questions right above it and their values are coming through to the script without a problem. For some reason, my script doesn't like the variable "intcredit".

Can someone help me out? I copied and pasted one of the other radio buttons and modified it for this variable.

This is the script which contains the form.



require_once ('mysql_connect.php');

if (isset($_POST['submitted'])) {
$errors = array();

//validate form data
if (empty($_POST['downpmt'])) {
$errors[] = 'Please enter a down payment.';
} else {
$_SESSION['downpmt'] = escape_data($_POST['downpmt']);

$_SESSION['loan_amount'] = 0;
$_SESSION['cltv'] = 0;
$_SESSION['ltv'] = 0;

$_SESSION['loan_amount'] = $_SESSION['purchaseprice'] - $_SESSION['downpmt'];
$_SESSION['cltv'] = $_SESSION['loan_amount'] / $_SESSION['purchaseprice'];
$_SESSION['ltv'] = $_SESSION['cltv'];

<p><b>Your Information:</b></p>

<tr><td><b>Purchase Price:</b></td><td>&nbsp;&nbsp;</td><td><?php echo number_format($_SESSION['purchaseprice'],2); ?></td></tr>
<tr><td><b>Planned Closing Date:</b></td><td>&nbsp;&nbsp;</td><td><?php echo $_SESSION['date']; ?></td></tr>
<tr><td><b>Location:</b></td><td>&nbsp;&nbsp;</td><td><?php echo $_SESSION['location']; ?></td></tr>
<tr><td><b>Down Payment:</b></td><td>&nbsp;&nbsp;</td><td><?php echo number_format($_SESSION['downpmt'],2); ?></td></tr>
<tr><td><b>Loan Amount:</b></td><td>&nbsp;&nbsp;</td><td><?php echo number_format($_SESSION['loan_amount'],2); ?></td></tr>
<tr><td><b>CLTV:</b></td><td>&nbsp;&nbsp;</td><td><?php echo number_format($_SESSION['cltv'] * 100,2); ?>%</td></tr>
<tr><td><b>LTV:</b></td><td>&nbsp;&nbsp;</td><td><?php echo number_format($_SESSION['ltv'] * 100,2); ?>%</td></tr>
<p>Please answer the following questions to see your loan options.</p>

<form name="my_form" id="my_form" action="searchrates.php" method="post">

<p><label for="propuse">Property use:</label>
<select name="propuse" size="1"">
<option value="Home">as a Home</option></SELECT></p>

<p><label for="proptype">Property type:</label>
<select name=proptype>
<option value="Single Family">Single Family Residence</option>
<option value="Condo">Condominium-less than 4 stories</option></select></p>

<p><label for="bincome">Borrower<br>Gross Monthly Income (before taxes):</label> <input type="text" name="bincome" size="15" maxlength="15" /></p>
<p><label for="cincome">Co-Borrower<br>Gross Monthly Income (before taxes):</label> <input type="text" name="cincome" size="15" maxlength="15" /></p>
<table border=0 cellpadding=0 cellspacing=0>
<tr><td><b>Credit History:</b>&nbsp;&nbsp;</td>
<select name="fico">
<option value=""></option>
<option value=720>Excellent&nbsp;&nbsp;(over 720) </option>
<option value=700>Very Good&nbsp;&nbsp;(700-719)</option>
<option value=680>Good&nbsp;&nbsp;(680-699)</option>
<option value=620>Fair&nbsp;&nbsp;(620-679)</option>
<option value=619>Poor&nbsp;&nbsp;(below 619)</option>
<td width=25><b>&nbsp;&nbsp;&nbsp;OR</b></td><td>&nbsp;&nbsp;</td>
<td><b>Approximate credit score:</b>&nbsp;&nbsp;</td>
<td><input type=text name=ficonum size=3 maxlength=3 value=""></td></tr>

<tr><td colspan=2><p style="line-height: 20px;"><b>Are you willing to document your income during the loan process?</b><br>
<INPUT TYPE=RADIO name=docincome VALUE=Yes checked>&nbsp;<b>I will document</b> my income for the lender.<BR>
<INPUT TYPE=RADIO name=docincome VALUE=No >&nbsp;<b>I will not document</b> my income. I understand stated loans are subject to higher interest
<tr><td colspan=2><p style="line-height: 20px;"><b>Do you plan to escrow?</b><br>
<INPUT TYPE=RADIO NAME=escrow VALUE=Yes checked>&nbsp;Yes, I will escrow.<BR>
<INPUT TYPE=RADIO NAME=escrow VALUE=No >&nbsp;No, I will not escrow.</p></td></tr>

<tr><td colspan=2><p style="line-height: 20px;"><b>If closing on or before the 5th of the month, do you want an interest credit? (First mortgage payment will be at the beginning of the next month. Ex: closing date is 6/5/2007, first payment is on 7/1/2007)</b><br>
<INPUT TYPE=RADIO NAME=intcredit VALUE=Yes checked>&nbsp;Yes, I want an interest credit.<BR>
<INPUT TYPE=RADIO NAME=intcredit VALUE=No >&nbsp;No, I do not want an interest credit.</p></td></tr>

<tr><td><input type="submit" name="btnSubmit" id="btnSubmit" value="Submit to see loan options for my scenario" class="btn" onfocus="this.blur()" />
<input type="hidden" name="submitted" value="TRUE" /></td></tr></table>
<script language="JavaScript" type="text/javascript">
var fields = document.my_form.elements;

fields["fico"].onblur = function(){
if(this.selectedIndex > 0){fields["ficonum"].disabled = "disabled";} else{fields["ficonum"].disabled = false;} }

fields["ficonum"].onblur = function(){
if(this.value != ""){fields["fico"].disabled = "disabled";} else{fields["fico"].disabled = false;} }

function reSet(){
fields["fico"].disabled = false;
fields["ficonum"].disabled = false;

document.my_form.onreset = reSet;
document.my_form.onsubmit = function(){ if(fields["fico"].selectedIndex > 0 && fields["ficonum"].value != ""){window.alert("You must choose only one of those two variants!"); return false;} else{return true;} } //--> </script> </body> </html>

This script processes the form. I only included the top half of the script which is a bunch of echo statements. The value for "intcredit" is not appearing in the echo statement. The rest of the script is useless if I can't see the value for this variable.




echo "Purchase Price: $_SESSION[purchaseprice]<br>";
echo "Down Payment: $_SESSION[downpmt]<br>";
echo "Loan Amount: $_SESSION[loan_amount]<br>";
echo "Closing Date: $_SESSION[date]<br>";
echo "Days in Month: $_SESSION[days_in_month]<br>";
echo "Days Left in Month: $_SESSION[days_left_in_month]<br>";
echo "LTV: $_SESSION[ltv]<br>";
echo "CLTV: $_SESSION[cltv]<br>";
echo "Property Use: $_SESSION[propuse]<br>";
echo "Property Type: $_SESSION[proptype]<br>";
echo "Borrower Income: $_SESSION[bincome]<br>";
echo "Co-Borrower Income: $_SESSION[cincome]<br>";
echo "FICO: $_SESSION[fico]<br>";
echo "FICO Score: $_SESSION[ficonum]<br>";
echo "Document Income: $_SESSION[docincome]<br>";
echo "Escrow: $_SESSION[escrow]<br>";
echo "Interest Credit: $_SESSION[intcredit]<br>";echo "<hr>";

As you can see the radio button code is identical to the other two and the echo statement is identical to the two above.

Can someone help me out? Thank you.

06-10-2007, 04:31 PM
Without starting a session I'm suprised that you don't get undefined index's on all of your session requests.
Are you sure you want a $_SESSION value requested, or a $_POST/$_GET request instead? Since the second script processes the code from the first which does not create a $_SESSION['intcredit'], you are trying to point to a value in an array that does not exist. Thats where your trouble is at.

06-11-2007, 12:01 PM

Thank you for the reply. After taking a long break from this, I realized I had another script which was forgotten. This script takes my form variables and validates, posts and creates the session variables. The script was forgotten because the name of the script needs to be changed. It's not named properly.