I'm getting undefined index errors on the $_POST variables. I.E. $_POST['hostname']. I know kinda why I'm getting them, but is there a way to keep the php and form in the same file and not get these errors?
<html>
<head>
<title>Install Forum</title>
</head>
<body>
<h1>Please enter your database information</h1>
<form action='install.php' method='post'>
Hostname: <input type='text' name='hostname'><br/>
MySQL User: <input type='text' name='dbuser'><br/>
MySQL Pass: <input type='password' name='dbpassword'><br/>
<input type='submit' name='submit' value='Submit'><br/>
</body>
</html>
<?php
include_once("config.php");
$date = date('Y-m-d');
//Database Variables
$dbhost = strip_tags($_POST['hostname']);
$dbuser = strip_tags($_POST['dbuser']);
$dbpass = strip_tags($_POST['dbpassword']);
$submit = isset($_POST['submit']);
Wrap your PHP code in an if
with an isset
condition. This way, the code will only be run if the form has been submitted:
if(isset($_POST['submit']))
{
include_once("config.php");
$date = date('Y-m-d');
//Database Variables
$dbhost = strip_tags($_POST['hostname']);
$dbuser = strip_tags($_POST['dbuser']);
$dbpass = strip_tags($_POST['dbpassword']);
$submit = isset($_POST['submit']);
}