if(!z){
          alert("You must enter at least two characters for the address");
          }
          var major = document.getElementById('major').value; 
        var z = /[a-z]{2,100}$/.test(major);
        if(!z){
          alert("You must enter at least two characters for the major");
          }
    }
        
  </script>

<?php 
if (isset($_REQUEST['pn'])) {
    include "personClass.php";
    $obj = new persons();
    $person_name = $_REQUEST['pn'];
    $person_id = $_REQUEST['pid'];
    $address = $_REQUEST['aid'];
    $major = $_REQUEST['mj'];
    if (!$obj->add_person($person_name, $person_id, $address, $major)) {
        echo "Error adding" . mysql_error();
    } else {
        echo " {$person_name} has successfully being added to the database";
    }
}
?>

</div>

    } else {
        $style = "";
    }
    echo "<tr {$style} >";
    echo "<td><span class='clickspot' onclick='getDesc({$row['person_id']})'>{$row['person_name']}<span></td>";
    echo "<td>{$row['person_id']}</td>";
    echo "<td>{$row['address']}</td>";
    echo "<td>{$row['major']}</td>";
    echo "<td><a href='ed.php'>edit</a> -- <a href='searchStudent.php?person_name={$row['person_name']}'>delete</a></td>";
    echo "</tr>";
    $row = $obj->fetch();
    $i++;
}
if (isset($_REQUEST['person_name'])) {
    echo $_REQUEST['person_name'];
    $obj = new persons();
    $person_name = $_REQUEST['person_name'];
    if (!$obj->delete_person($person_name)) {
        echo "Error deleting" . mysql_error();
    } else {
        header("location:searchStudent.php");
    }
}
?>
    
</div>
</body>
</html>