-1

This is my form html code

<form id="register-form" action="submit.php" method="POST" style="display: block;">
    <h2>REGISTER</h2>
    <div class="form-group">
        <input type="text" name="fullname" id="fullname" tabindex="1" class="form-control" placeholder="Full Name">
    </div>
    <div class="form-group">
        <input type="text" name="username" id="username" tabindex="1" class="form-control" placeholder="Username">
    </div>
    <div class="form-group">
        <input type="email" name="email" id="email" tabindex="1" class="form-control" placeholder="Email Address">
    </div>
    <div class="form-group">
        <input type="password" name="password" id="password" tabindex="2" class="form-control" placeholder="Password">
    </div>
    <div class="form-group">
        <div class="row">
            <div class="col-sm-6 col-sm-offset-3">
                <input type="submit" name="register-submit" id="register-submit" tabindex="4" class="form-control btn btn-register" value="Sign Up Now">
            </div>
        </div>
    </div>
</form>

This is my submit php

<?php
if ($_SERVER['REQUEST_METHOD']=='POST') {
echo "there's a post submitted";

if(isset($_POST["username"]) && isset($_POST["email"]) && isset($_POST["password"]) && isset($_POST["password"])){
    require_once './DB_Functions.php';
    $db = new DB_Functions();

    // receiving the post params
    $name = $_POST['fullname'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $username = $_POST['username'];


    // create a new user
    $user = $db->storeUser($name, $email, $password, $username);
    if ($user) {
        // user stored successfully
        $_SESSION["uid"] = $user["unique_id"];
        $_SESSION["name"] = $user["name"];
        $_SESSION["email"] = $user["email"];
        $_SESSION["nickname"] = $user["nickname"];
        haeader("Location","details.php");
    } else {
        // user failed to store
        echo "Problem.";
    }

}
else {
    // in here i wantted to see which parameters are missing.
    echo ($_POST["username"]);
    echo ($_POST["fullname"]);
    echo ($_POST["email"]);
    echo ($_POST["password"]);
}
}
?>

And this is the response from submit.php

there's a post submitted Notice: Undefined index: username in C:\xxx\submit.php on line 32

Notice: Undefined index: fullname in C:\xxx\submit.php on line 33

Notice: Undefined index: email in C:\xxx\submit.php on line 34

Notice: Undefined index: password in C:\xxx\submit.php on line 35

Why I can't receive values from submit.php?

Community
  • 1
  • 1
Mert Doe
  • 549
  • 5
  • 15

2 Answers2

0
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    echo "there's a post submitted";

    if (isset($_POST["username"]) && isset($_POST["email"]) && isset($_POST["password"]) && isset($_POST["password"])) {
        require_once './DB_Functions.php';
        $db = new DB_Functions();

        // receiving the post params
        $name = $_POST['fullname'];
        $email = $_POST['email'];
        $password = $_POST['password'];
        $username = $_POST['username'];


        // create a new user
        $user = $db->storeUser($name, $email, $password, $username);
        if ($user) {
            // user stored successfully
            $_SESSION["uid"] = $user["unique_id"];
            $_SESSION["name"] = $user["name"];
            $_SESSION["email"] = $user["email"];
            $_SESSION["nickname"] = $user["nickname"];
            haeader("Location", "details.php");
        } else {
            // user failed to store
            echo "sikinti";
        }
    } else {
        // in here i wantted to see which parameters are missing.

        /* this following code is expected to throw an error because of the conditions on the if statement above, so it doesn't exist.*/
        /*you may transfer this echos inside the if statement then you may change the logical operators to || to verify each parameters*/
        echo ($_POST["username"]);
        echo ($_POST["fullname"]);
        echo ($_POST["email"]);
        echo ($_POST["password"]);
    }
}
-1

For PHPStorm Ide $_POST doesn't work.

https://intellij-support.jetbrains.com/hc/en-us/community/posts/207521565--POST-not-working-on-localhost?page=1#community_comment_115000473844

This bug wasted my 5 hours.

Mert Doe
  • 549
  • 5
  • 15