$_POST returns Undefined index

Asked

Viewed 512 times

0

Well, I’m trying to make a login system, but my $_POST returns "Undefined index" error and everywhere I find the same thing and still error.

Html:

<form action="submit.php" method="post">


<div id="login-columns">
    <div id="login-column-1">
        <label for="credentials-email">Email</label>
        <input tabindex="2" type="text" name="credentials.username" id="credentials-email" value="">
    </div>

    <div id="login-column-2">
        <label for="credentials-password">Senha</label>
        <input tabindex="3" type="password" name="credentials.password" id="credentials-password">
    </div>

    <div id="login-column-3">
        <input type="submit" value="Login">
        <a href="#" tabindex="4" class="button" id="credentials-submit"><b></b><span>Login</span></a>
    </div>...

And php: echo $_POST['credentials.username'];

for me there is no error, but even so it does not return the input value

  • 1

    I’ve never seen a dot used as a separator in this kind of situation... and trade for credentials-username?

  • 1

    It automatically switches the point to underscore

  • Test there to make a foreach creating a new array where you replace (can be with str_replace) the underscore by a point. And then put $_GET = $seu_new_array.

  • I didn’t understand, how to use the foreach to convert the . in _?

  • 1

    To get the value do as @Zebradomal spoke use $_POST['credentials_username'] can test in Submit.php by giving a print_r($_POST); so you’ll see the array keys.

  • It worked :D Vlw.

  • 1

    Dude, you have two options, either do what I told you with foreach, or use credentials_username.

  • As I wrote upstairs, php converts the stitch to underscore. You can continue using the dot there in get, but then you need to make a new array where you replace the underscore with a dot and then assign $_GET the value of your new array.

  • 1

    In the Post I had to put _ but in the Input continued . as well as the Zebradomal and lost spoke

Show 4 more comments

1 answer

-1


It works:

 <form action="go2.php" method="post">
 <input type=text name="valor.test.op" value="" />
 <input type="submit" value="Login">
 </form>

And on the PHP side

 <?php

 echo $_POST['valor_test_op'];

?>

But even if this is right, I find it best to avoid the points in the name, in HTML

  • Peter, I already got it but I don’t understand why you have to avoid . (dot) in Html?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.