Home » Php » php – display a blank page after submit

php – display a blank page after submit

Posted by: admin February 25, 2020 Leave a comment

Questions:

index.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    <title>Document</title>
</head>
<body>

<form  action="check.php" method="post">
<input type="text" name="name" id="name" placeholder="first name">
<input type="text" name="email" id="email">
<button type="submit" name="submit" id="dsubmit">submit</button>
<p class="form-message"></p>
</form>

</body>
</html>

check.php file

<?php

if(isset($_POST['submit'])){

    $name = $_POST['name'];
    $mail = $_POST['mail'];

    echo "name is " .$name;


}
?>

after i submit it redirects to the check.php file but it displays nothing on that page.
so i changed check.php file to this

if(empty($_POST['submit'])){
    $name = $_POST['name'];
    $mail = $_POST['mail'];

     echo "name is " .$name;

}

this display Undefined index: name and Undefined index: mail

How to&Answers: