mysqli_connect(): (HY000/2003): Can't connect to MySQL server on 'domain name' (111)

匿名 (未验证) 提交于 2019-12-03 02:03:01

问题:

Im very new to php and my SQL, and am having trouble connecting to my SQL Database. Im getting the following error when i submit my HTML Form.

mysqli_connect(): (HY000/2003): Can't connect to MySQL server on 'domain name' (111) 

Here is my php code:

    $name=$_POST['name'];   $email=$_POST['email'];   $location=$_POST['location'];   mysqli_connect("domain_name", "1645347_data", "*password omitted*") or die(mysql_error()); //error getting thrown at this line  mysqli_select_db("1645347_data") or die(mysql_error());   mysqli_query("INSERT INTO `data` VALUES ('$name', '$email', '$location')");   Print "Your information has been successfully added to the database.";   ?> 

As you can see, it is a very simple php script (as I am following a tutorial).

Can anybody see why i would be getting this error? im more than happy to provide additional information if requested.

回答1:

It looks like your script is trying to connect "domain_name", but it can't find that server because it's not listed on the DNS's. Is your server on the same machine? In that cause you need to replace domain_name with localhost, 127.0.0.1 or the ip of the server.

ALSO MAKE SURE TO SANITIZE YOUR INPUTS BEFORE YOU RUN THE SQL COMMANDS!!!!

This should help.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!