-1

I know there are similar questions asked but none of them are helping in my case.

I have a form written as such:

    <div class = "Contact">
        <form action="formprocessor.php" method="post">
            <label>Name: </label>
            <input name="name" type="text" size="25" />

            <label>Course: </label>
            <input name="course" type="text" size="25" />

            <label>Book: </label>
            <input name="book" type="text" size="255" />

            <label>Price: </label>
            <input name="price" type="text" size="7" />

            <label>Email: </label>
            <input name="email" type="text" size="255" />

            <label>Phone #: </label>
            <input name="phone" type="text" size="12" />

            <input name="mySubmit" type="submit" value="Submit!" />
        </form>
    </div>

and relevant PHP code from formprocessor.php:

<?php
$name = $_POST["name"];
$course = $_POST["course"];
$book = $_POST["book"];
$price = $_POST["price"];
$email = $_POST["email"];
$phone = $_POST["phone"];

echo $name;
?>

Clicking the sumbit button on the form gives me these errors:

Notice: Undefined index: name in /Users/Jose/PhpstormProjects/334 Final Project/formprocessor.php on line 3

Notice: Undefined index: course in /Users/Jose/PhpstormProjects/334 Final Project/formprocessor.php on line 4

Notice: Undefined index: book in /Users/Jose/PhpstormProjects/334 Final Project/formprocessor.php on line 5

Notice: Undefined index: price in /Users/Jose/PhpstormProjects/334 Final Project/formprocessor.php on line 6

Notice: Undefined index: email in /Users/Jose/PhpstormProjects/334 Final Project/formprocessor.php on line 7

Notice: Undefined index: phone in /Users/Jose/PhpstormProjects/334 Final Project/formprocessor.php on line 8

Any help is appreciated. Thanks in advance

Jose
  • 9
  • 5
  • Is `formprocessor.php` the same script that displays the form? – Barmar Mar 29 '16 at 03:42
  • No, the form is printed through a function in another PHP file. `formprocessor.php` only prints contents of `$_POST` – Jose Mar 29 '16 at 03:45
  • Then I can't see a reason why this is happening. Have you tried checking what's being sent using the Network tab of Developer Tools? – Barmar Mar 29 '16 at 03:46
  • Seems like the post data is not the expected one. Do print_r($_POST); in your PHP file and check the array values. – Ivan Mar 29 '16 at 03:35
  • The output is `Array ()` – Jose Mar 29 '16 at 03:41

2 Answers2

0
<?php
if(isset($_POST['mySubmit']))
{
    $name = $_POST["name"];
    $course = $_POST["course"];
    $book = $_POST["book"];
    $price = $_POST["price"];
    $email = $_POST["email"];
    $phone = $_POST["phone"];

    echo $name;
}
?>
Barmar
  • 741,623
  • 53
  • 500
  • 612
Drudge Rajen
  • 7,584
  • 4
  • 23
  • 43
0
<?php
$name   = isset($_POST["name"]) ? $_POST["name"] : '';
$course = isset($_POST["course"]) ? $_POST["course"] : '';
$book   = isset($_POST["book"]) ? $_POST["book"] : '';
$price  = isset($_POST["price"]) ? $_POST["price"] : '';
$email  = isset($_POST["email"]) ? $_POST["email"] : '';
$phone  = isset($_POST["phone"]) ? $_POST["phone"] : '';

echo $name;
?>
J.K
  • 1,382
  • 1
  • 11
  • 27