2016-04-23 189 views
-2

我正在創建一個網頁。該網頁有一個表單,表單數據通過.php頁面發送,保存在MySQL數據庫中。我正在使用XAMPP。
這裏是我的腳本:XAMPP/MySQL:數據庫連接時出錯

$dbc = mysqli_connect('http://localhost:8080/127.0.0.1','root',' ','aliendatabase'); 
    $query = "INSERT INTO aliens_abduction (first_name,last_name,when_it_happened, how_long, " . 
    "how_many, alien_description, what_they_did, fang_spotted, other, email) " . 
    "VALUES ('Nadreen', 'Muhammad Ali', 'since birth', '21 years', 'all of them', 'sad cretures', " . 
    "'ruined me', 'yes', 'I may have seen your dog. Contact me.', " . 
    "'[email protected]')"; 
    $result = mysqli_query($dbc,$query) 
    or die('Error querying database.'); 
    mysqli_close($dbc); 

我不斷收到這些錯誤:

Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: 
The requested name is valid, but no data of the requested type was found 

和:

mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: 
The requested name is valid, but no data of the requested type was found 
+4

'http:// localhost:8080/127.0.0.1' - 只使用'localhost''。 RTM http://php.net/manual/en/function.mysqli-connect.php –

+1

你應該使用'localhost'而不是那個URL。密碼真的是'空白'還是你想用空字符串''? – GiftZwergrapper

+0

http://albertech.net/2011/05/fix-php_network_getaddresses-getaddrinfo-failed-name-or-service-not-known/ 試試這個 – Naruto

回答

0

相反的:

$dbc = mysqli_connect('http://localhost:8080/127.0.0.1','root',' ','aliendatabase'); 

使用此:

$dbc = mysqli_connect('localhost','root','','aliendatabase'); 
+0

無關的mysql行協議。那裏的空間可能是一個問題,因爲我們都已經在評論中概述了。編輯:你編輯。 –