我有文件"1.php"和文件"2.php"...
在"1.php"中,有一个HTML表单:
<form action="2.php" method="post">
<div class="form-group">
<label for="db_username">Field 1:</label>
<input type="text" class="form-control" id="db_username">
</div>
<div class="form-group">
<label for="db_password">Field 2:</label>
<input type="password" class="form-control" id="db_password">
</div>
<div class="form-group">
<label for="db_passphrase">Field 3:</label>
<input type="text" class="form-control" id="db_passphrase">
</div>
<button type="submit" class="btn btn-default">Next</button>
</form>
Run Code Online (Sandbox Code Playgroud)
在"2.php"中,动作必须在PHP中应用..就像:
<?php
// Process of Step "1"
$db_username = $_POST['db_username'];
$db_password = $_POST['db_password'];
$db_passphrase = $_POST['db_passphrase'];
if( !isset($db_username) || !isset($db_password) || !isset($db_passphrase) ) {
header("Location: 1.php?error=1");
die();
}
?>
Run Code Online (Sandbox Code Playgroud)
然而..的值$_POST['db_username'],$_POST['db_password']并且$_POST['db_passphrase']是空的...
您需要使用该name属性以便以后访问$_POST数据,如下所示:
<input type="text" class="form-control" id="db_username" name="db_username">
Run Code Online (Sandbox Code Playgroud)