Php Single page form processing issue
<p>(Sorry for my bad english)</p>

<p>Well, I've 3 errors in my code.  </p>

<p>Error's: </p>

<ol>
<li>First of all it's show : Notice: Undefined index: form in C:\xampp\htdocs\evantechbd\index.php on line 461. When i run this form.  </li>
<li>if any error found it's show error message, well, but correct field is empty. Example: In this form there is 4 fields. a) upload image, b) select discussion c) subject and d) message. Suppose you upload a image, select a discussion and write a subject but forgot to write message. Then It's show "Message Required" and every filed is empty. I don't want empty field which is correct.  </li>
<li>After successfully submitted the form it's show "Discussion was submitted ". But after that if i refresh the page it's send the data to database. But I did not click submit button. why this happen?  </li>
</ol>

<p>Here is my code:</p>

<pre><code>&lt;?php
if ($_POST['form'] == "Submit") {
    $err       = array();
    $filed     = addslashes($_FILES['file']['tmp_name']);
    $img_named = addslashes($_FILES['file']['name']);
    $img_type  = addslashes($_FILES['file']['type']);
    @$imgd = addslashes(file_get_contents($_FILES['file']['tmp_name']));

    function getExtension($str)
    {
        $i = strrpos($str, ".");
        if (!$i) {
            return "";
        }
        $l   = strlen($str) - $i;
        $ext = substr($str, $i + 1, $l);
        return $ext;
    }
    $extension        = getExtension($img_named);
    $extension        = strtolower($extension);
    $image_named_uniq = uniqid() . '.' . $extension;
    $upload_path_dis  = 'user/manage/discussionimg/';

    $diss = $_POST['type'];
    $sub  = $_POST['sub'];
    $msg  = $_POST['msg'];
    $date = "On " . date("F Y h:i:s A");

    if (!isset($_SESSION['uname']))
        $err[] = "You need to login";

    else {
        $uname = $_SESSION['uname']; //session username

        if (empty($sub) &amp;&amp; empty($msg) &amp;&amp; empty($filed))
            $err[] = "All field required";
        else {
            if (empty($sub))
                $err[] = "Subject Requried";

            if (empty($msg))
                $err[] = "Message Requried";

            if (empty($filed))
                $err[] = "SORRY, you have to be upload a image";
        }
    }

    if (!empty($err)) {
        foreach ($err as $er) {
            echo "&lt;font color=red&gt;$er&lt;/font&gt;&lt;br/&gt;";
        }
    }

    else {
        $sql = mysql_query("INSERT INTO discussion VALUES ('', '$imgd', '$image_named_uniq', 
'$diss', '$sub', '$msg', '$uname', '$date' ) ");
        if (!$sql)
            echo "Can't submit your discussion" . mysql_error();

        if (!move_uploaded_file($_FILES['file']['tmp_name'], $upload_path_dis . $image_named_uniq)) {
            die('File Not Uploading');
        } else {
            echo "Discussion was submitted";
        }
    }
}
?&gt;
</code></pre>

<p>Many Thanks for your help!!<br>
Kanta.</p>
