0
<html>
<body>
index.php
<form action="config.php" method="Post">
<table>
    <tr><td>DB Host: <input type="text" name="dbhost"></></tr>
    <tr><td>DB Name: <input type="text" name="dbname"></td></tr>
    <tr><td>DB pass: <input type="text" name="dbpass"></td></tr>
    <tr><td><button type="submit" name="submit"> Submit</button></td></tr>
</table>
</form>

<?php 
config.php
$dbhost = $dbname = $dbpass = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $dbname = test_input($_POST["dbname"]);
    $dbpass = test_input($_POST["dbpass"]);

    $con = mysql_connect('$dbhost', '$dbname', '$dbpass');
    if (!$con) {
        echo "could not connect" . mysql_error();
    } else {
        echo "Processing...";
    }
}
    function test_input($data)![enter image description here][1]
    {
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        return $data;
    }
  ?>

this is the error:

could not connectphp_network_getaddresses: getaddrinfo failed: No such host is known.

1

1 Answer 1

1

change

$con = mysql_connect('$dbhost', '$dbname', '$dbpass');

to

$con = mysql_connect($dbhost, $dbname, $dbpass);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.