-1

When I tried running process.php file, I get the following error:

Notice: Undefined index: first_name in C:\xampp\htdocs\addemp\process.php on line 3

Notice: Undefined index: email in C:\xampp\htdocs\addemp\process.php on line 5

Code:-

<?php

echo $_POST['first_name'];
echo '<br />';
echo $_POST['email'];

Kindly someone help to resolve this issue as early as possible.

<!DOCTYPE html>
<html>
<head>

    <style>
    label{display:inline-block;width:100px;margin-bottom:10px;} 
    </style>
    <title>Add Employee</title>
</head>
<body>
    <form action="" method="post">
        <label>First Name</label> <input name="first_name" type="text"><br>
        <label>Last Name</label> <input name="last_name" type="text"><br>
        <label>Department</label> <input name="department" type="text"><br>
        <label>Email</label> <input name="email" type="text"><br>
        <input type="submit" value="Add Employee">
    </form>
</body>
</html>
VaLLe.
  • 160
  • 1
  • 6

1 Answers1

1

As affaz said: put php file name in action in form.

Explanation:

Everything works fine if your index.php file content is:

<!DOCTYPE html>
<html>
<head>
    <title>Add Employee</title>
    <style>
        label{
            display:inline-block;
            width:100px;
            margin-bottom:10px;
        }
    </style>
</head> 
<body>
    <form action="action.php" method="post">
        <label>First Name</label><input name="first_name" type="text"><br>
        <label>Last Name</label> <input name="last_name" type="text"><br>
        <label>Department</label> <input name="department" type="text"><br>
        <label>Email</label> <input name="email" type="text"><br>
        <input type="submit" value="Add Employee">
    </form>
</body>
</html>

and action.php file content is:

<?php
echo $_POST['first_name'];
echo '<br />';
echo $_POST['email'];
?>

everything works fine.