Hello:
I have a form where there are two select boxes. One select box displays the loan programs available. The second select box displays the lenders.
When I submit the form and it ran correctly, I want to display a success statement something like “Rate updated for Program: <name> AND Lender: <name>.
I tested my script and the insert/update works perfectly. My problem is my success statement. It shows: Rate Updated for Program: $program AND Lender: $lender! The $program and $lender variable should show the name of the program and the name of the lender which was selected from the select box.
In the update query, you will see that the program_id and lender_id passed without a problem because the tables do get updated correctly. I don’t know why the name of both the program($program) and lender($lender) are not working.
Can someone help me out? The code is posted below.
Thank you in advance for all your help.
[code=php]
<?php
$page_title = ‘Rate Insert and Update’;
session_start();
$status = $_SESSION[“status”];
switch ($status)
{
case “Not logged”:
include “login.php”;
break;
case “”:
include “login.php”;
break;
case “Logged”:
include (‘header4.html’);
echo ‘<h2>Rate Update Screen</h2>’;
require_once (‘mysql_connect.php’);
if (isset($_POST[‘submitted’])) {
$errors = array();
//check for program.
if (!isset($_POST[‘program’])) {
$error[] = ‘You forgot to select a program.’;
} else {
$program = escape_data($_POST[‘program’]);
}
//check for lender.
if (!isset($_POST[‘lender’])) {
$error[] = ‘You forgot to select a program.’;
} else {
$lender = escape_data($_POST[‘lender’]);
}
//check for rate.
if (!is_numeric($_POST[‘rate1’])) {
$errors[] = ‘You forgot to enter a rate.’;
} else {
$rate1 = (float) $_POST[‘rate1’];
}
//check for price.
if (!is_numeric($_POST[‘price1’])) {
$errors[] = ‘You forgot to enter a price.’;
} else {
$price1 = (float) $_POST[‘price1’];
}
//check for rate.
if (!is_numeric($_POST[‘rate2’])) {
$errors[] = ‘You forgot to enter a rate.’;
} else {
$rate2 = (float) $_POST[‘rate2’];
}
//check for price.
if (!is_numeric($_POST[‘price2’])) {
$errors[] = ‘You forgot to enter a price.’;
} else {
$price2 = (float) $_POST[‘price2’];
}
//check for rate.
if (!is_numeric($_POST[‘rate3’])) {
$errors[] = ‘You forgot to enter a rate.’;
} else {
$rate3 = (float) $_POST[‘rate3’];
}
//check for price.
if (!is_numeric($_POST[‘price3’])) {
$errors[] = ‘You forgot to enter a price.’;
} else {
$price3 = (float) $_POST[‘price3’];
}
//check for rate.
if (!is_numeric($_POST[‘rate4’])) {
$errors[] = ‘You forgot to enter a rate.’;
} else {
$rate4 = (float) $_POST[‘rate4’];
}
//check for price.
if (!is_numeric($_POST[‘price4’])) {
$errors[] = ‘You forgot to enter a price.’;
} else {
$price4 = (float) $_POST[‘price4′];
}
if (empty($errors)) {
// Add new lender.
$query = “UPDATE test SET
program_id=’$_POST[program_id]’, lender_id=’$_POST[lender_id]’, rate1=’$rate1′, price1=’$price1′,
rate2=’$rate2′, price2=’$price2′, rate3=’$rate3′, price3=’$price3′, rate4=’$rate4′, price4=’$price4′
WHERE program_id=’$_POST[program_id]’ AND lender_id=’$_POST[lender_id]'”;
$result = mysql_query ($query) or die (mysql_error());
if (mysql_affected_rows() == 1) { // If it ran OK.
// Finish the page.
echo ‘<h3>Rate Updated for Program: $program AND Lender: $lender!</h3>’;
}
else $query = “INSERT INTO test (program_id, lender_id, rate1, price1, rate2, price2, rate3, price3,
rate4, price4)
VALUES (‘$_POST[program_id]’, ‘$_POST[lender_id]’, ‘$rate1’, ‘$price1’, ‘$rate2’, ‘$price2’,
‘$rate3’, ‘$price3’, ‘$rate4’, ‘$price4’)”;
$result = mysql_query ($query) or die (mysql_error());
if (mysql_affected_rows() == 1) { // If it ran OK.
// Finish the page.
echo ‘<h3>Rate Added!</h3>’;
}
}
else {
echo ‘<p><font color=”red”>Submission could not be completed. Please try again!</font></p>’;
}
}
?>
<form action=”admin_rate_update.php” method=”post”>
<table>
<tr><td>Loan Program</td>
<td><select name=”program_id”>
<option value=””>Please Select</option>
<?php
$sql = “SELECT * FROM loan_program”;
$resultset = mysql_query( $sql ) or die(mysql_error());
while( $row = mysql_fetch_assoc( $resultset ) ) {
$program_id = $row[‘id’];
$program = $row[‘program’];
print ‘<option value=”‘ . $program_id . “” >” . $program . “</option>n”;
}
?>
</select></td>
</tr>
<tr><td>Lender</td>
<td><select name=”lender_id”>
<option value=””>Please Select</option>
<?php
$sql = “SELECT * FROM lender”;
$resultset1 = mysql_query( $sql ) or die(mysql_error());
while( $row1 = mysql_fetch_assoc( $resultset1 ) ) {
$lender_id = $row1[‘id’];
$lender = $row1[‘lender’];
print ‘<option value=”‘ . $lender_id . “” >” . $lender . “</option>n”;
}
?>
</select></td>
</tr>
<tr><td></td></tr>
<tr><td>Rate</td><td>Price</td>
<tr><td> <input type=”text” name=”rate1″ size=”7″ maxlength=”10″ /></td>
<td><input type=”text” name=”price1″ size=”7″ maxlength=”10″/></td></tr>
<tr><td> <input type=”text” name=”rate2″ size=”7″ maxlength=”10″ /></td>
<td><input type=”text” name=”price2″ size=”7″ maxlength=”10″/></td></tr>
<tr><td> <input type=”text” name=”rate3″ size=”7″ maxlength=”10″ /></td>
<td><input type=”text” name=”price3″ size=”7″ maxlength=”10″/></td></tr>
<tr><td> <input type=”text” name=”rate4″ size=”7″ maxlength=”10″ /></td>
<td><input type=”text” name=”price4″ size=”7″ maxlength=”10″/></td></tr>
<tr><td><label for=”blank”> </label></td><td><input type=”submit” name=”btnSubmit” id=”btnSubmit” value=”Submit” class=”btn” />
<input type=”hidden” name=”submitted” value=”TRUE” /></td></tr>
</table>
</form>
<p><a href=”welcome.php”>Return to Main Menu</a></p>
<?php
include(‘footer3.html’);
?>
<?
}
?>