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;
}
?>
這是錯誤:嘗試在php中使用輸入值填充數據庫連接參數。給這個消息
could not connectphp_network_getaddresses: getaddrinfo failed: No such host is known.