rahimli
rahimli

Reputation: 1472

html form post gives empty array

I am trying to post data from html form (html code is inside index.php file) into add_student.php file which is supposed to just print $_POST array using print_r function. But there is always empty array on result.

index.php

<html>

<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="css/styles.css">
    <link rel="stylesheet" href="css/font-awesome.css">
</head>
<body>

<div class="contact col-md-12" id="get_in_touch">
    <div class="col-md-10 col-md-offset-1">
        <div class="contact_title">
            <h2>
                Add a student
            </h2>
        </div>
        <div class="contact_container">
            <div class="contact_form col-md-8">
                <form action="add_student.php" method="post">
                    <input name="student_name"   type="text"  placeholder="FULL NAME" class="input1"/>
                    <input name="student_email"  type="text"  placeholder="E-MAIL" class="input1"/>
                    <input name="password"  type="text"  placeholder="PASSWORD" class="input1"/>
                    <input name="major"  type="text"  placeholder="MAJOR" class="input1"/>
                    <input name="group"  type="text"  placeholder="GROUP NUMBER" class="input1"/>
                    <input name="submit"  type="submit" value="ADD STUDENT"/>
                </form>
            </div>
        </div>
    </div>
</div>

</body>

add_student.php:

<?php
print_r($_POST);
?>

Why I always get empty array?

Upvotes: 2

Views: 353

Answers (2)

Demi&#235;n Drost
Demi&#235;n Drost

Reputation: 173

Perhaps it will work if you use an include as the following:

include_once add_student.php;

And then use index.php as the form action. IF you later want to proceed to another page, add a header <url> at the bottom of the included script.

Make sure you check if the submit button has been pressed in the add_student.php script isset($_POST['submit']) Data might get lost in the travel from to page

Upvotes: 0

rahimli
rahimli

Reputation: 1472

It seems that problem is in PHPStorm localhost port. When you just enter in browser the address of index.php it works perfectly. However when I run code from IDE it returns empty array.

Upvotes: 1

Related Questions