Form not POSTing values

2020-04-19 12:00发布

Form:

<form id="register" method="POST" action="pro/register.php">
    <input type="text" maxlength="30" placeholder="Username" id="user" /><br />
    <input type="email" maxlength="64" placeholder="Email" id="email" /><br />
    <input type="password" placeholder="Password" id="pass1" /><br />
    <input type="password" placeholder="Confirm Password" id="pass2" /><br />
    <input type="submit" value="Register" id="submit_register" />
</form>

pro/register.php page:

$user = $_POST['user'];
$email = $_POST['email'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];

//Debug only
echo "<strong>Details:</strong><br>";
echo $user.", ".$email.", ".$pass1.", ".$pass2."<br>";

if($pass1!==$pass2){
    header('Location:../login.php?alert=pass');
    exit;
}

$hash = hash('sha256', $pass);

include "../inc/functions.php";

$salt = createSalt();
$hash = hash('sha256', $salt . $hash);

include "../inc/connect.php";

$stmt = $dbh->prepare("INSERT INTO `users` 
                (`username`,`email`,`password`,`salt`,`pic`) 
                VALUES (:username,:email,:password,:salt,:pic)");
$stmt->bindParam(':username',$user);
$stmt->bindParam(':email',$email);
$stmt->bindParam(':password',$hash);
$stmt->bindParam(':salt',$salt);
$stmt->bindParam(':pic',$pic);
$stmt->execute();
$dbh=NULL;

header('Location:../login.php?alert=newreg');

Output when form is posted:

Details:
, , , 

标签: php html forms
2条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-04-19 12:16

You must include the 'name' attribute in your form inputs, this is what determines where the value goes in $_POST.

查看更多
甜甜的少女心
3楼-- · 2020-04-19 12:33
<input type="text" maxlength="30" placeholder="Username" id="user" name="user"/><br />

try adding the name field.

查看更多
登录 后发表回答