gpt4 book ai didi

php - 尝试使用输入值来填写 php 中的数据库连接参数。发出此消息

转载 作者:行者123 更新时间:2023-11-29 12:40:02 26 4
gpt4 key购买 nike

<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;
}
?>

这是错误:

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

1

最佳答案

改变

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

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

关于php - 尝试使用输入值来填写 php 中的数据库连接参数。发出此消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26249765/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com