I've been trying to make a setup form for a Database, however I've run into a problem where I keep constantly getting a notice undefined index on my variables. My form is:
if(!isset($dbServer)) {
echo "
<form method='POST'>
<div class='formHolder'>
<h2>Create the MySQL structure</h2>
<h3>
Input the address of the SQL server
</h3>
<label>SQL Server: </label>
<input type='text' name='dbServer' placeholder='e.g. localhost' />
";
}
if (!isset($dbUsername) && !isset($dbPassword)) {
echo "
<h3>
Input the login to the Database so DIY CMS can connect
</h3>
<label>SQL Database Username: </label>
<input type='text' name='dbUsername' placeholder='e.g. admin' />
<br />
<label>SQL Database Password: </label>
<input type='password' name='dbPassword' placeholder='e.g. root' />
<br />
<input type='submit' name='submit' value='Done' />
</div>
</form>
";
}
And then underneath that I have variables from the post:
$dbServer = $_POST['dbServer'];
$dbUsername = $_POST['dbUsername'];
$dbPassword = $_POST['dbPassword'];
After the variables there are a few if statements and some more PHP that uses the variables, but every single time I get undefined index as soon as I load the page, and I'd rather not have them appear.
My guess is that PHP is running through all the code and then sees that my variables are undefined since the POST hasn't happened yet. But I'm not sure, any explanation as to why I'm getting the errors on my variables and potential solutions are appreciated.