PHP:
$errors = array();
$db = "";
if (isset($_POST['saveuserForm'])) {
$host = $_POST['host'];
$username = $_POST['username'];
$password = $_POST['password'];
$databasename = $_POST['databasename'];
if($host == "") {
$errors[] = "Host can not be blank";
}
if($username == "") {
$errors[] = "Username can not be blank";
}
if($password == "") {
$errors[] = "Password can not be blank";
}
if($databasename == "") {
$errors[] = "Database Name can not be blank";
}
if ($host !== "" && $username !== "" && $password !== "" && $databasename !== "") {
$db = mysqli_connect($host, $username, $password, $databasename);
$connectionstring = "
<?php
\$dbname = \"d" . $databasename . "\";
\$dbuser = \"w" . $username . "\";
\$dbpass = \"f" . $password . "\";
\$dbhost = \"s" . $host . "\";
\$db = mysqli_connect(\$dbhost, \$dbuser, \$dbpass, \$dbname );
if (mysqli_connect_errno()) {
echo \"Failed to connect to MySQL: \" . mysqli_connect_error();
}
";
echo file_put_contents("../includes/dbname.php", $connectionstring);
}
}
HTML:
<ul>
<?php
foreach ($errors as $value) {
echo "<li>$value</li>";
}
?>
</ul>
<form action="install.php" method="post">
<h3>Database Info:</h3>
<div>
<label class="desc" id="title3" for="host">
Host:
</label>
<div>
<input id="host" name="host" type="text" spellcheck="false" value="" maxlength="255" tabindex="3">
</div>
</div>
<div>
<label class="desc" id="title3" for="Username">
Username:
</label>
<div>
<input id="Username" name="Username" type="text" spellcheck="false" value="" maxlength="255" tabindex="3">
</div>
</div>
<div>
<label class="desc" id="title3" for="password">
Password
</label>
<div>
<input id="password" name="password" type="Password" spellcheck="false" value="" maxlength="255" tabindex="3">
</div>
</div>
<div>
<label class="desc" id="title3" for="Database Name">
Database Name:
</label>
<div>
<input id="Database Name" name="Database Name" type="text" spellcheck="false" value="" maxlength="255" tabindex="3">
</div>
</div>
<div>
<div>
<input id="saveForm" name="submitdb" type="submit" value="Submit">
</div>
</div>
</form>
Result:
<?php
$dbname = "d";
$dbuser = "w";
$dbpass = "f";
$dbhost = "s";
$db = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname );
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
Hello, i need some help on add php code into a php file the result is not showing the string that is from the form i need it to show in the proper place in the result.
if you see in the connectionstring variable i have varibles that are suppost to display in there but they are not display the contents of the string in my result.
I need it to display the input from the user thank you
Thank You