when I click on "submit", I always get an error saying that "Object not Found!" However, if I change $action to $_SERVER['PHP_SELF']: i.e.
<form action='<?php echo $action; ?>' method='post'>
to
<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>
it will work. However, in this situation, we cannot submit the form to "sighup.php" if there is no error.
<!DOCTYPE html>
<html>
<head>
<title>Testpage</title>
</head>
<body>
<?php
$uid_err="";
if(isset($_POST['submit'])) {
if(empty($_POST['uid'])) {
$uid_err="This field cannot be empty!";
$action=$_SERVER['PHP_SELF'];
} else {
$action="signup.php";
}
}
?>
<form action='<?php echo $action; ?>' method='post'>
<input type="txt" name="uid"><?php echo $uid_err; ?><br>
<button type="submit" name="submit">Submit</button>
</form>
</body>
</html>