Hello:
I’m having some trouble and I’ve stared at these scripts for hours and I can’t seem to find what’s causing the problem. I was hoping an objective second pair of eyes could help me out. The solution is probably quite simple and I’m missing the obvious.
I have two scripts. For simplicity, let’s call them script 1 and script 2. Script 1 produces a list of rates and prices for a selected loan program. In addition, script 1 also adds an Edit link.
The Edit link is going to bring you to script 2. The Edit link pass a variable called “rateid” which is an auto-incremented field. Basically it’s the row for the record. Well, when I click Edit, I receive one of my error messages that is in the script. [I]This page has been accessed in error
So, if I want to edit record #2, script 1 passes rateid = 2 to script 2 which should show a form in which editing can be done. The error message appears. For some reason, the rateid from script 1 isn’t passing to script 2 and I can’t seem to understand why.
Can someone help me out? I have the code for both scripts.
—
Script 1 (Edit link and passes rateid to script 2) – this script works – I highlighted the line of code in blue which should pass the rateid.
[CODE]
<?php
require_once (‘mysql_connect.php’);
if ( (isset($_GET[‘id’])) && (is_numeric($_GET[‘id’])) ) {
$id = $_GET[‘id’];
}
else {
echo ‘<h1>Page Error</h1>
<p>This page has been accessed in error.</p><p><br /><br /></p>’;
exit();
}
$query = “SELECT mortgage_type.id, mortgage_type.type, rates.rate_id, rates.mtg_type_id, rates.rate,
rates.price, rates.date_entered, rates.time_entered
FROM mortgage_type
LEFT JOIN rates
ON mortgage_type.id = rates.mtg_type_id
WHERE mortgage_type.id = $id”;
$result = @mysql_query ($query) or die (mysql_error());
echo ‘<h2>Current Loan Rates</h2>’;
echo ‘<table align=”center” cellspacing=”0″ cellpadding=”5″>
<tr>
<td align=”left”><b>Edit</b></td>
<td align=”left”><b>Rate</b></td>
<td align=”left”><b>Price</b></td>
</tr>
‘;
while ($row = @mysql_fetch_array($result, MYSQL_ASSOC)) {
$id = $row[‘id’];
$type = $row[‘type’];
$rateid = $row[‘rate_id’];
$mtgid = $row[‘mtg_type_id’];
$rate = $row[‘rate’];
$price = $row[‘price’];
$date = $row[‘date_entered’];
$time = $row[‘time_entered’];
echo ‘
<td align=”left[COLOR=”Blue”]”><a href=”newrate.php?rateid=’ . $rateid . ‘”>Edit</a>[/COLOR]</td>
<td align=”left”>’ . $rate . ‘</td>
<td align=”left”>’ . $price . ‘</td>
</tr>
‘;
}
echo ‘</table>’;
echo ‘<p><a href=”welcome.php”>Return to Main Menu</a><br /><br />’;
@mysql_free_result ($result); // Free up the resources.
mysql_close(); // Close the database connection.
?>
—-
Script 2 (this should be the form to allow you to update a specific record based on rateid from script 1 after clicking Edit.
[CODE]
<?php
if ( (isset($_GET[‘rateid’])) && (is_numeric($_GET[‘rateid’])) ) { //retrieved from view_programs_1.php
$rateid = $_GET[‘rateid’];
} elseif ( (isset($_POST[‘rateid’])) && (is_numeric($_POST[‘rateid’])) ) { //form was submitted
$rateid = $_POST[‘rateid’];
} else { //no valid ID, kill script
echo ‘<h1″>Page Error</h1>
<p class=”error”>[COLOR=”Red”]This page has been accessed in error.[/COLOR]</p><p>< /br>< /br></p>’;
exit();
}
require_once (‘mysql_connect.php’);
if (isset($_POST[‘submitted’])) {
$errors = array();
//check for rate.
if (!is_numeric($_POST[‘rate’])) {
$errors[] = ‘You forgot to enter a rate.’;
} else {
$rate = (float) $_POST[‘rate’];
}
//check for price.
if (!is_numeric($_POST[‘price’])) {
$errors[] = ‘You forgot to enter a price.’;
} else {
$price = (float) $_POST[‘price’];
}
if (empty($errors)) {
// Make the query.
$query = “UPDATE rates SET rate=’$rate’, price=’$price’, date=CURRENT_DATE, time=CURRENT_TIME
WHERE rate_id=$rateid”;
$result = @mysql_query ($query); // Run the query.
if (mysql_affected_rows() == 1) { // If it ran OK.
// Print a message.
echo ‘<p><h2>Rates Updated.</h2></p>
<p><a href=”welcome.php”>Return to Main Menu</a><br /><br />’;
} else { // If it did not run OK.
echo ‘<span class=”bold1″>System Error</span>
<p class=”error”>The user could not be edited due to a system error. We apologize for any inconvenience.</p>’; // Public message.
echo ‘<p>’ . mysql_error() . ‘<br /><br />Query: ‘ . $query . ‘</p>
<p><a href=”welcome.php”>Return to Main Menu</a><br /><br />’; // Debugging message.
include (‘footer3.html’);
exit();
}
}
} // End of submit conditional.
// Always show the form.
// Retrieve the user’s information.
$query = “SELECT mtg_type_id, rate, price, date, time
FROM rates WHERE rate_id=$rateid”;
$result = @mysql_query ($query); // Run the query.
if (@mysql_num_rows($result) == 1) { // Valid load ID, show the form.
// Get the user’s information.
$row = @mysql_fetch_array ($result, MYSQL_NUM);
// Create the form.
echo ‘<hr><span class=”bold2″>Update Rates</span>
<form action=”newrate.php” method=”post”>
<p><label for=”rate”>Rate:</label> <input type=”text” name=”rate” size=”7″ maxlength=”10″ value=”‘ . $row[1] . ‘” /></p>
<p><label for=”price”>Price:</label><input type=”text” name=”price” size=”7″ maxlength=”10″ value=”‘ . $row[2] . ‘” /></p>
<p><label for=”blank”> </label><input type=”submit” name=”submit” value=”Submit” /></p>
<input type=”hidden” name=”submitted” value=”TRUE” />
<input type=”hidden” name=”rateid” value=”‘ . $rateid . ‘” />
</form>’;
} else { // Not a valid user ID.
echo ‘<span class=”bold1″>Page Error</span><hr>
<p class=”error”>This page has been accessed in error.</p><p><br /><br /></p>
<p><a href=”welcome.php”>Return to Main Menu</a><br /><br />’;
}
mysql_close(); // Close the database connection.
?>
If someone can take a look at this and help me figure out what’s going on, I’ll grealy appreciate it.
Thank you for all the help.