Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are my form variables not passing through POST?

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.

like image 798
ahnbizcad Avatar asked Dec 08 '22 11:12

ahnbizcad


2 Answers

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 />
like image 104
Patato Avatar answered Dec 11 '22 01:12

Patato


the ploblem is not at register.php

you can try to write like this:

if ( isset($_POST['username']) ) {
$postUsername = $_POST['username'];
echo $postUsername;
}
like image 38
kempjone Avatar answered Dec 11 '22 00:12

kempjone