Q:

product id and staff id will not change when search button is clicked

i have this code that works as a form. so whenever i have selected product id and staff id and when i click search, the product description, price will appear(the info is taken from the database). and once i am done typing in the rest of the information for quantity, pos and receipt number, i will click submit. all these information will then go into my database sql. 
but i am facing a problem whereby whenever i have searched for the product id and staff id in the database, it will refresh. so the product id and staff id will go back to what it originally is, which means the wrong ids will be inserted. how do i make the page not refresh/change the ids whenever search is being clicked but still get the product description and price from the database? or how do i not make the variables (staff id and product id) be lost upon refresh?
<div id="login-form">
<form method="post">

<?php

    mysql_connect('localhost', 'root', '');
    mysql_select_db('ishop');

    $sql = "SELECT DISTINCT product_id FROM tbl_product";
    $result = mysql_query($sql);
    echo "<table align='center' width='40%' border='0'>";
    echo "<tr>";
    echo "<td width='100'>";

    echo "Product ID: <select name='product_id' class='form-control input-lg'>";
    while ($row = mysql_fetch_array($result))
    {
        echo "<option value='" . $row['product_id'] ."'>" . $row['product_id'] ."</option>";
    }

    echo "</select>";
    echo "</td>";
    echo "</tr>";

    mysql_connect('localhost', 'root', '');
    mysql_select_db('ishop');

    $sql = "SELECT DISTINCT UserName FROM tbl_user";
    $result = mysql_query($sql);
    echo "<table align='center' width='40%' border='0'>";
    echo "<tr>";
    echo "<td width='100'>";

    echo "Staff ID: <select name='UserName' class='form-control input-lg'>";
    while ($row = mysql_fetch_array($result))
    {
        echo "<option value='" . $row['UserName'] ."'>" . $row['UserName'] ."</option>";
    }

    echo "<tr>";
    echo "<td>";
    echo "<input name='lookup' type='submit' id='lookup' value='Search'>";

    echo "</td>";
    echo "</tr>";

    echo "</form>";

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

        $product_id = $_POST['product_id'];

        mysql_connect('localhost', 'root', '');
        mysql_select_db('ishop');

        $sql = "SELECT DISTINCT product_des FROM tbl_product where product_id ='$product_id'";
        $result = mysql_query($sql);

        echo "<table align='center' width='40%' border='0'>";
        echo "<tr>";
        echo "<td width='100'>";

        echo "Product Description: <select name='product_des' class='form-control input-lg'>";
        while ($row = mysql_fetch_array($result))
        {
            echo "<option value='" . $row['product_des'] ."'>" . $row['product_des'] ."</option>";
        }

        echo "</form>";

        echo "</td>";
        echo "</tr>";

}

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

        $product_id = $_POST['product_id'];

        mysql_connect('localhost', 'root', '');
        mysql_select_db('ishop');

        $sql = "SELECT DISTINCT price FROM tbl_product where product_id ='$product_id'";
        $result = mysql_query($sql);

        echo "<table align='center' width='40%' border='0'>";
        echo "<tr>";
        echo "<td width='100'>";

        echo "Price: <select name='price' class='form-control input-lg'>";
        while ($row = mysql_fetch_array($result))
        {
            echo "<option value='" . $row['price'] ."'>" . $row['price'] ."</option>";
        }

        echo "</form>";

        echo "</td>";
        echo "</tr>";

}

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

        $product_id = $_POST['product_id'];

        mysql_connect('localhost', 'root', '');
        mysql_select_db('ishop');

        echo "<table align='center' width='40%' border='0'>";
        echo "<tr>";
        echo "<td width='100'>";

        echo "Quantity: <input type ='text' name='qty' class='form-control input-lg'>";
        echo "</td>";
        echo "</tr>";

}

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

        $product_id = $_POST['product_id'];

        mysql_connect('localhost', 'root', '');
        mysql_select_db('ishop');

        echo "<table align='center' width='40%' border='0'>";
        echo "<tr>";
        echo "<td width='100'>";

        echo "POS: <input type ='text' name='POS' class='form-control input-lg'>";
        echo "</td>";
        echo "</tr>";

}

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

        $product_id = $_POST['product_id'];

        mysql_connect('localhost', 'root', '');
        mysql_select_db('ishop');

        echo "<table align='center' width='40%' border='0'>";
        echo "<tr>";
        echo "<td width='100'>";

        echo "Receipt Number: <input type ='text' name='ReceiptNumber' class='form-control input-lg'>";
        echo "</td>";
        echo "</tr>";

}
?>

<tr>
<td><button type="submit" name="btn-submit">Submit</button></td>
</tr>

</table>
</form>
</div>

A:

One way to achieve this is to either use a session or a cookie.
Using a $_SESSION would look something like this:
$_SESSION['product_id'] = $product_id;

For the session you need to remember to start it by placing session_start(); at the top of your page. Another thing to be aware of this that you'd need to make a logic that if you "willingly" change the product id / staff id also updated the $_SESSION values. (This also concerns when using cookies).
And for a $_COOKIE something like this:
setcookie("TestCookie", $value, time()+3600);  /* expire in 1 hour */

