Hello:
I’m trying to write a script to update a table. I have two scripts. Script 1 has the user select a program and a lender. When they click Submit, we go to Script 2 which extracts the current information for the selected program and lender.
The objective is to allow the user update the information for the selected program and lender. I am basically losing my mind. I have tried a number of ways to get the update to work and I’m not having any luck. Everytime, I would type in the new information and click Submit, I get various messages, such as undefined index.
I was hoping someone can help me out. I’m not sure what else to do. Something tells me that I need to have a Script 3 which would do the actual update. I was hoping to have the update performed in Script 2.
The code for both scripts are at the end. The versions you see reflect the point to which the scripts are working. In this case, you will see the current information for the program and lender. The scripts do not contain any of the update attempts I’ve made. I made so many, I wouldn’t even know what to display.
I was hoping by looking at what works, someone can point me in the right direction on how to proceed with the update portion.
Script 1: Two select boxes for the user to select a program and lender.
[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’);
require_once (‘mysql_connect.php’);
?>
<form action=”test1.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><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’);
?>
<?
}
?>
====
Script 2: Passes the program and lender from script 1 and displays the current information for that program and lender.
[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’);
require_once (‘mysql_connect.php’);
$pid = $_POST[‘program_id’];
$lid = $_POST[‘lender_id’];
$sql = “SELECT * FROM loan_program WHERE id=$pid”;
$resultset = mysql_query( $sql ) or die(mysql_error());
while( $row = mysql_fetch_assoc( $resultset ) ) {
$program_id = $row[‘id’];
$program = $row[‘program’];
}
$sql = “SELECT * FROM lender WHERE id=$lid”;
$resultset1 = mysql_query( $sql ) or die(mysql_error());
while( $row1 = mysql_fetch_assoc( $resultset1 ) ) {
$lender_id = $row1[‘id’];
$lender = $row1[‘lender’];
}
echo “Update Rate<br><br>$program<br>$lender”;
$sql = “SELECT * FROM test WHERE program_id=$pid AND lender_id=$lid”;
$resultset2 = mysql_query( $sql ) or die(mysql_error());
$row2 = mysql_fetch_assoc( $resultset2 );
$rate1 = $row2[‘rate1’];
$price1 = $row2[‘price1’];
$rate2 = $row2[‘rate2’];
$price2 = $row2[‘price2’];
$rate3 = $row2[‘rate3’];
$price3 = $row2[‘price3’];
$rate4 = $row2[‘rate4’];
$price4 = $row2[‘price4’];
?>
<form action=”test1.php” method=”post”>
<table>
<tr><td>Rate</td><td>Price</td>
<tr><td> <input type=”text” name=”rate1″ size=”7″ maxlength=”10″ value=”<?php echo $rate1; ?>” /></td>
<td><input type=”text” name=”price1″ size=”7″ maxlength=”10″ value=”<?php echo $price1; ?>” /></td></tr>
<tr><td> <input type=”text” name=”rate2″ size=”7″ maxlength=”10″ value=”<?php echo $rate2; ?>” /></td>
<td><input type=”text” name=”price2″ size=”7″ maxlength=”10″ value=”<?php echo $price2; ?>” /></td></tr>
<tr><td> <input type=”text” name=”rate3″ size=”7″ maxlength=”10″ value=”<?php echo $rate3; ?>” /></td>
<td><input type=”text” name=”price3″ size=”7″ maxlength=”10″ value=”<?php echo $price3; ?>” /></td></tr>
<tr><td> <input type=”text” name=”rate4″ size=”7″ maxlength=”10″ value=”<?php echo $rate4; ?>” /></td>
<td><input type=”text” name=”price4″ size=”7″ maxlength=”10″ value=”<?php echo $price4; ?>” /></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’);
?>
<?
}
?>
Now, all I need is for the user to type over the current information, click Submit, and update the table. This is where I am failing and could use some help/guidance.