usamember usamember - 1 year ago 57
HTML Question

PHP not getting any response from the form on the previous page

I have the file "1.php" and the file "2.php" ...

In "1.php", there's a HTML form:

<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 class="form-group">
<label for="db_password">Field 2:</label>
<input type="password" class="form-control" id="db_password">
<div class="form-group">
<label for="db_passphrase">Field 3:</label>
<input type="text" class="form-control" id="db_passphrase">
<button type="submit" class="btn btn-default">Next</button>

While in "2.php", the action must be applied in PHP .. like that:

// 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");

However .. the values of
is empty...

Answer Source

You need to use the name attribute to later access the $_POST data, as in:

<input type="text" class="form-control" id="db_username" name="db_username">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download