I am have created a form and having problems validating it as I am getting a few errors when I try to preview it in the browser. 

**The errors**

```
Undefined index: username in  on line 269
Undefined index: email in  on line 270
Undefined index: fname in  on line 271
Undefined index: lname in  on line 272
Undefined index: pnumber in  on line 273
Undefined index: address in  on line 274
Undefined index: password in  on line 275

**my php scripts starts on line  35 and ends on line 131**
 <!--DB connection-->     (line 35)
<?php
$localhost = "localhost";
$dbuser = "student";
$dbpass = "student";
$dbname = "Curiosity_Pizza";

$connect = mysqli_connect($localhost,$dbuser,$dbpass)or die ("Could not connect to database!");;
mysqli_select_db($connect, "$dbname" );
?>

<!-- inserting form data in to DB-->

<?php
$username =$_POST['username'];
$email =$_POST['email'];
$fname =$_POST['fname'];
$lname =$_POST['lname'];
$pnumber =$_POST['pnumber'];
$address =$_POST['address'];
$password = sha1($_POST['password']);   

$inssert = 'INSERT into client(username, email, fname, lname, pnumber ,address,  password) VALUES ("'.$username.'","'.$email.'","'.$fname.'","'.$lname.'", "'.$pnumber.'", "'.$address.'","'.$password.'")';

mysqli_query($connect,$inssert);    
?>

<!--Registration Valadation-->
<?php

//define varibles and sst to empty (w3Schhols)
$usernameErr = $emailErr = $fnameErr = $lnameErr = $pnumberErr = $addressErr = $passwordErr = "";
$username = $email = $fname = $lname = $pnumber = $address = $password = "";

if ($_SERVER["REQUEST_METHOD"]== "POST"){
    $username = test_input($_POST["username"]);
    $email =  test_input($_POST["email"]);
    $fname = test_input($_POST["fname"]);
    $lname = test_input($_POST["lname"]);
    $pnumber = test_input($_POST["pnumber"]);
    $address = test_input($_POST["address"]);
    $password = test_input($_POST["passoerd"]); 
}

function test_input($data){
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

if ($_SERVER["REQUEST_METHOD"]== "POST"){
    if (empty($_POST["userename"])){
        $usernameErr = "Userename is a required field";
    }else{
     $username = test_input($_POST["username"]);
    }

    if (empty($_POST["email"])){
        $emailErr = "Email is a required field";
    }else{
     $email = test_input($_POST["email"]);
    }

    if (empty($_POST["fname"])){
        $fnameErr = "First Name is a required field";
    }else{
     $fname = test_input($_POST["fname"]);
    }

    if (empty($_POST["lanme"])){
        $lnameErr = "Last Name is a required field";
    }else{
     $lname = test_input($_POST["lname"]);
    }

    if (empty($_POST["pnumber"])){
        $pnumberErr = "Phone Number is a required field";
    }else{
     $pnumber = test_input($_POST["$number"]);
    }

    if (empty($_POST["address"])){
        $addressErr = "Address is a required field";
    }else{
     $address = test_input($_POST["address"]);
    }

    if (empty($_POST["$password"])){
        $passwordErr = "Password is a required field";
    }else{
     $password = test_input($_POST["password"]);
    }
}   (line 131)

**My html/form not sure if its relevant low**
<form method="post"  action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" />
                                <table width="600" border="0">
                                  <tr>
                                    <th><label for="Username">Username:</label></th>
                                    <td><input type="text" name="username" />
                                    <span class="error">*<?php echo $usernameErr;?></span></td>
                                  </tr>
                                  <tr>
                                    <th><label for="email">email:</label></th>
                                    <td><input type="email" name="email" />
                                    <span class="error">*<?php echo $emailErr;?></span></td>
                                  </tr>
                                  <tr>
                                    <th><label for="fname">First Name:</label></th>
                                    <td><input type="text" name="fname" />
                                    <span class="error">*<?php echo $fnameErr;?></span></td>
                                  </tr>
                                  <tr>
                                    <th><label for="lname">Last Name:</label></th>
                                    <td><input type="text" name="lname" />
                                    <span class="error">*<?php echo $lnameErr;?></span></td>
                                  </tr>
                                  <tr>
                                    <th><label for="pnumber">Phone Number:</label></th>
                                    <td><input type="number" name="pnumber" />
                                    <span class="error">*<?php echo $pnumberErr;?></span></td>
                                  </tr>
                                  <tr>
                                    <th><label for="address">Address:</label></th>
                                    <td><input type="text"  name="address" />
                                    <span class="error">*<?php echo $addressErr;?></span></td>
                                  </tr>
                                  <tr>
                                    <th><label for="password">Passowrd:</label</th>                                   <td><input type="password"  name="password"   />
                                    <span class="error">*<?php echo       $passwordErr;?></span></td>
                                  </tr>                                                                         
                                  <tr>
                                    <td><input type="submit" name="Submit"</td>
                                  </tr>
                                </table>
                            </form>

```

I have tried reading the other posts on here but have not found anything that would work.