Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8409101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:48:51+00:00 2026-06-09T23:48:51+00:00

I wasn’t sure what else to call the title…I have a PHP page that

  • 0

I wasn’t sure what else to call the title…I have a PHP page that accesses a certain MySQL database, pulls the values from the table, and places them in an HTML form (POST method – PHP_SELF). The user can then view the values, alter them as they wish, and submit them. The page then takes those values and updates the MySQL database. Everything works perfectly except that when the user submits and the page goes to show the new updated variables, it still shows the old values. The user is forced refresh the page before the new variables show up. I thought that PHP was perhaps not deleting the variables, so I unset all stored variables after the script was over and it’s still not working. I ever tried putting a sleep timer before the script started, and that didn’t work either. I’d appreciate any suggestions. Here is my script just for reference:

<html>
<body>

<?php

$sql = "SELECT * FROM lease";
$result = mysql_query($sql);

?>

<form id="lease_update" method="post" action="<?php echo htmlentities($PHP_SELF); ?>">
<table>
<tr>
<th>Account</th>
<th>Car Lease</th>
<th>Radio Lease</th>
<th>Misc. Charges</th>
</tr>

<?php
    while($rows = mysql_fetch_array($result)){
 ?>

<tr>
<td><input type="text" name="account[]" value="<?php echo $rows['accnt']; ?>" /></td>
<td><input type="int" name="car_lease[]" value="<?php echo $rows['car']; ?>" /></td>
<td><input type="int" name="radio_lease[]" value="<?php echo $rows['radio']; ?>" />     </td>
<td><input type="int" name="misc_lease[]" value="<?php echo $rows['misc']; ?>" /></td>
<input type="hidden" name="lease_ID[]" value="<?php echo $rows['ID']; ?>" />
</tr>

<?php
    }
?>
</table>
<input type="submit" value="Update" name="lease_update" />

<?php

if(isset($_POST['lease_update'])){

$account = $_POST['account'];
$car_lease = $_POST['car_lease'];
$radio_lease = $_POST['radio_lease'];
$misc_lease = $_POST['misc_lease'];
$lease_ID = $_POST['lease_ID'];

//Get Array Lengths For Each Section
$A = count($lease_ID);

//Update Lease Information
$i = 0;
while($i < $A){
    if(!mysql_query('UPDATE lease SET accnt = "' .$account[$i]. '", car = "' .$car_lease[$i]. '", radio = "' .$radio_lease[$i]. '", misc = "' .$misc_lease[$i]. '"  WHERE ID = ' .$lease_ID[$i]))
        die('Error: ' .mysql_error());
    $i++;
}
unset($_POST);
    unset($rows);
    unset(result);

}
?>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:48:52+00:00Added an answer on June 9, 2026 at 11:48 pm

    You are displaying the data from the database before you update it.

    It is normally good practice to do all your database connectivity at the top of the page, then display the results.

    In your code (even if a user has submitted an update), you query the data, pull it from database and display it, then run the update with what the user submitted.

    Changing your code to this should do the trick (Do read the note below though):

    <html>
    <body>
    
    <?php
    
    if(isset($_POST['lease_update'])){
    
    $account = $_POST['account'];
    $car_lease = $_POST['car_lease'];
    $radio_lease = $_POST['radio_lease'];
    $misc_lease = $_POST['misc_lease'];
    $lease_ID = $_POST['lease_ID'];
    
    //Get Array Lengths For Each Section
    $A = count($lease_ID);
    
    //Update Lease Information
    $i = 0;
    while($i < $A){
        if(!mysql_query('UPDATE lease SET accnt = "' .$account[$i]. '", car = "' .$car_lease[$i]. '", radio = "' .$radio_lease[$i]. '", misc = "' .$misc_lease[$i]. '"  WHERE ID = ' .$lease_ID[$i]))
        die('Error: ' .mysql_error());
        $i++;
    }
    unset($_POST);
        unset($rows);
        unset(result);
    
    }
    
    
    $sql = "SELECT * FROM lease";
    $result = mysql_query($sql);
    
    ?>
    
    <form id="lease_update" method="post" action="<?php echo htmlentities($PHP_SELF); ?>">
    <table>
    <tr>
    <th>Account</th>
    <th>Car Lease</th>
    <th>Radio Lease</th>
    <th>Misc. Charges</th>
    </tr>
    
    <?php
        while($rows = mysql_fetch_array($result)){
     ?>
    
    <tr>
    <td><input type="text" name="account[]" value="<?php echo $rows['accnt']; ?>" /></td>
    <td><input type="int" name="car_lease[]" value="<?php echo $rows['car']; ?>" /></td>
    <td><input type="int" name="radio_lease[]" value="<?php echo $rows['radio']; ?>" />     </td>
    <td><input type="int" name="misc_lease[]" value="<?php echo $rows['misc']; ?>" /></td>
    <input type="hidden" name="lease_ID[]" value="<?php echo $rows['ID']; ?>" />
    </tr>
    
    <?php
        }
    ?>
    </table>
    <input type="submit" value="Update" name="lease_update" />
    
    </body>
    </html>
    

    Bad note – your code is wide open to injection attacks. You are using form data with no verification. That’s a big red flag. Secondly, you are using deprecated mysql_* functions. Your code should be using mysqli_* functions or better yet move to PDO. It is much safer and you will be able to do a lot more with it.

    Edit 2: The page IS being updated after the user submits the form, but the page you display to the user is querying the database before you update it – and using that to display the page to the user.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wasn't even sure how to title this right. I have a page that
I wasn't sure what to title this question. Here's my goal: On page one,
I wasn't sure how to word this exactly. But I have a model that
I wasn't sure how to call this. Basically I have a Label widget. It
I have a strange problem and I wasn't sure how to word the title.
I wasn't sure exactly how to phrase the question Title. I have this block
That title wasn't very descriptive; I wasn't sure how to shorten my question... Let's
I wasn't sure about my questions name. I have an HTML page I got
Wasn't sure how to title this, so please change it :) If I have
I wasn't even sure how to phrase this so you'll have to forgive me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.