Onchange Select
<p>Hello I have a problem with the following code:</p>

<pre><code>&lt;form name = 'form' method = 'post' action =''&gt;
    &lt;select name = "medicine" onChange = "this.form.submit();"&gt;
        &lt;?php
            $query =  mysql_query("SELECT  medicine, meddesc, exp_date FROM farm1_medicine_inventory");
            while($row=mysql_fetch_array($query)){
                echo "&lt;option value = '".$row['medicine']."'&gt;".$row['medicine']."&lt;/option&gt;";
            }
        ?&gt;
    &lt;/select&gt;
&lt;/form&gt;
</code></pre>

<p>My problem is that I have tried this code on a single page and it works by me being able to see that it refreshes/loads</p>

<p>But once I implement it with my other codes it just doesn't run. (no reload/refresh)</p>

<p>This is my php file where i want to insert the above code:</p>

<pre><code>    &lt;?

    //start a session
    session_start();
    error_reporting(0);
        $user  = $_SESSION['username'];
    if ($user) {
?&gt;&lt;?php
    }

else {
    die ("You are not logged in sir!");
    }

?&gt;
&lt;?php
    // create the parameters needed to connect to the mysql database server
    $host = 'localhost';
    $username = 'root';
    $password = '';
    $db = 'flockperformance';
    $table_name='farm1_medicine';

    // create the connection; if an error occurs display the error
    $connection = mysql_connect($host, $username, $password) or die(mysql_error());

    // select the database to use; if an error occurs display the error
    //$db = mysql_select_db($db) or die(mysql_error());
    $db = mysql_select_db($db) or die("Could not open a connection to the database server");

    // get the value of p


    if (isset($_REQUEST['submit']))
    {
        $id = $_REQUEST['id'];
        $dateused = date('Y-M-j');
        $medicine = $_REQUEST['medicine'];
        $meddesc = $_REQUEST['meddesc'];
        $exp_date = $_REQUEST['exp_date'];
        $quantity = $_REQUEST['quantity'];

    if(!$dateused OR !$medicine OR !$meddesc OR !$quantity){
        $message = "fill";
            }else {


        $query = "insert into $table_name set
                            medicine = '$medicine',
                            meddesc = '$meddesc',
                            exp_date = '$exp_date',
                            quantity = '$quantity',
                            dateused = '$dateused'
                            ";

                        $get= mysql_query("SELECT * FROM farm1_medicine_inventory where medicine = '$medicine'");
                        $getqty=mysql_fetch_assoc($get);
                        $newqty=$getqty['quantity']-$quantity;
                        $update=mysql_query("UPDATE farm1_medicine_inventory SET quantity='$newqty' where medicine = '$medicine'");
                    echo $newqty;

                $qry=mysql_query($query);

                    $message = "
                            &lt;p align='center'&gt;&lt;em&gt;&lt;strong&gt;$medicine and $quantity&lt;/strong&gt;&lt;/em&gt;
                            was successfully added...&lt;/p&gt;
                           ";

    }}
/*
    if ($p == 'Insert New')
    {
        // set the insert new flag to true
        $insertNew = true;
    }
*/
?&gt;
&lt;html&gt;
&lt;title&gt;Add Records&lt;/title&gt;
&lt;body bgcolor='orange'&gt;
&lt;font face='tahoma'&gt;
&amp;nbsp
&lt;h1 align='center'&gt;ADD Records - Farm 1&lt;/h1&gt;
&lt;h2 align='center'&gt;&lt;em&gt;Add a New Record to the Table&lt;/em&gt;&lt;/h2&gt;
&lt;form name='F1' method='post' action=''&gt;

    &lt;!-- &lt;input type='submit' name='p' value='Insert New'&gt;
    &lt;?
        $insertNew = true;
    ?&gt;
&lt;!--------------------------------------------------------------------------------------&gt;
&lt;? 
    if ($insertNew) // if the value of insertNew is true
    {
    ?&gt;
    &lt;hr&gt;
    &lt;br&gt;
    &lt;table align='center' width='75%' border cellspacing='2' cellpadding='2' bgcolor='white'&gt;


        &lt;tr&gt;
            &lt;td align='center'&gt;&lt;font face='tahoma' size='2'&gt;&lt;b&gt;Date Used&lt;/td&gt;
            &lt;td align='center'&gt;&lt;? echo date('Y-M-j');?&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td align='center'&gt;&lt;font face='tahoma' size='2'&gt;&lt;b&gt;Medicine&lt;/td&gt;
            &lt;td align="center"&gt;
                &lt;form name = 'form' method = 'post' action =''&gt;
                &lt;select name = "medicine" onChange = "this.form.submit();"&gt;
            &lt;?php
                $query =  mysql_query("SELECT  medicine, meddesc, exp_date FROM farm1_medicine_inventory");
                while($row=mysql_fetch_array($query)){
                echo "&lt;option value = '".$row['medicine']."'&gt;".$row['medicine']."&lt;/option&gt;";
            }
            ?&gt;
            &lt;/select&gt;
            &lt;/form&gt;
            &lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
            &lt;td align='center'&gt;&lt;font face='tahoma' size='2'&gt;&lt;b&gt;Medicine Description&lt;/td&gt;
            &lt;td align='center'&gt;&lt;input name='meddesc' 
            value = '&lt;? $query =  mysql_query("SELECT  medicine, meddesc, exp_date FROM farm1_medicine_inventory");
            $row=mysql_fetch_array($query);
            echo "" . $row['meddesc'] . "";
            ?&gt;' size='75%' maxlength='50'&gt;
            &lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
            &lt;td align='center'&gt;&lt;font face='tahoma' size='2'&gt;&lt;b&gt;Expiration Date:&lt;/td&gt;
            &lt;td align='center'&gt;&lt;input name='exp_date' size='75%' maxlength='50'&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
            &lt;td align='center'&gt;&lt;font face='tahoma' size='2'&gt;&lt;b&gt;Quantity:&lt;/td&gt;
            &lt;td align='center'&gt;&lt;input name='quantity' size='75%' maxlength='50'&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
            &lt;td align='center'&gt;&lt;input type='submit' name='submit' value='Save New Entry'&gt;&lt;/td&gt;
            &lt;td align = 'center'&gt;&lt;?

            echo "$message";

            ?&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/table&gt;
    &lt;br&gt;
    &lt;hr&gt;

    &lt;?
    }
    ?&gt;
&lt;!--------------------------------------------------------------------------------------&gt;
&lt;/form&gt;
&lt;/font&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
