scb998
scb998

Reputation: 909

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

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.

Upvotes: 2

Views: 16846

Answers (1)

Micah
Micah

Reputation: 119

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.

Upvotes: 3

Related Questions