5

I am sending form data through POST, but the corresponding POST variables are not set, and do not.

Also, when I store POST data into local PHP variables, I seem to be unable to use those variables. (Once I resolve the first issue, I have a feeling I will be able to user the variables too.)

My error messages output by the second page (see below) is:

Notice: Undefined variable: postUsername in (...somepath)\scripts\create-member.php on line 10

(Form page) :

<form action="scripts/create-member.php" method="POST">

        <input type="text" name"username" value="" placeholder="User Name"> <br />
        <input type="password" name"password" value="" placeholder="Password"> <br />
        <input type="password" name"passwordConfirm" value="" placeholder="Confirm Password"> <br />
        <!-- ?type email or type text -->
        <input type="email" name"email" value="" placeholder="Email" autofocus> <br />
        <input type="submit" name="submitRegistration" value="Register!">

    </form>

(Second page) scripts\create-member.php:

<?php

//!proper way to declare variables obtained from POST.
// Data from form "register.php"
if ( isset($_POST['username']) ) {
    $postUsername = $_POST['username'];
}


echo $postUsername;    // <-- this is line 10

?>

I've tried using isset() for the submit button too, but that didn't solve the problem. I've simplified the code by a lot here, and ran it testing it too.

ahnbizcad
  • 10,491
  • 9
  • 59
  • 85

3 Answers3

12

In your html code, you have missed = for name

name="username"

Instead of name"username"


Here's your fixed code.

<input type="text" name="username" value="" placeholder="User Name"> <br />
<input type="password" name="password" value="" placeholder="Password"> <br />
<input type="password" name="passwordConfirm" value="" placeholder="Confirm Password"> <br />
<!-- ?type email or type text -->
<input type="email" name="email" value="" placeholder="Email" autofocus> <br />
KeirDavis
  • 665
  • 2
  • 10
  • 32
Patato
  • 1,464
  • 10
  • 12
2

the ploblem is not at register.php

you can try to write like this:

if ( isset($_POST['username']) ) {
$postUsername = $_POST['username'];
echo $postUsername;
}
kempjone
  • 21
  • 1
0

I had a similar problem posting to an index.php file in a folder.

<form id="register" name="register" method="POST" action="/register">
// BROKEN

all $_POST vars were empty until I added a trailing forward slash to the form post action

<form id="register" name="register" method="POST" action="/register/">
// WORKS
Hivekey
  • 176
  • 6