MySQL / PHP:“无法连接到mysql,因为php_network_getaddresses:getaddrinfo失败:”

时间:2012-03-13 00:27:38

标签: php mysql include

尝试创建一个内置于轻量级框架中的简单用户注册表单。然而,当我按下注册时它返回这个:无法连接到mysql因为php_network_getaddresses:getaddrinfo失败:名称或服务未知。当我自己运行代码时,它工作得非常好,但是当我将它埋入我的框架中时它不起作用。我认为这与层次结构有关吗?我不习惯使用包含等,所以也可能是原因。 通过index.php?= register

访问文件

register.inc.php:domain.co.uk/web/includes/register.inc.php

    <?php # register.inc.php

/* 
 *  This is the register module.
 *  This page is included by index.php.
 */

// Redirect if this page was accessed directly:
if (!defined('BASE_URL')) {

    // Need the BASE_URL, defined in the config file:
    require_once ('../includes/config.inc.php');

    // Redirect to the index page:
    $url = BASE_URL . 'index.php';
    header ("Location: $url");
    exit;

} // End of defined() IF.
?>
<html>
      <h2>Registration:</h2>

<form action="../web/modules/register.php" method="post">

Pick a Username: <input type="text" name="username" size="20"><br>
Pick a Password: <input type="password" name="password" size="20"><br>
<input type="submit" value="Sign Up">
</form>
</html> 

register.php文件:domain.co.uk/web/modules/register.php

<?php
include("../includes/config.inc.php"); 

// connect to the mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db(DB_NAME)
or die ("Could not select database because ".mysql_error());

// check if the username is taken
$check = "select id from _test where username = '".$_POST['username']."';"; 
$qry = mysql_query($check) or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry); 
if ($num_rows != 0) { 
echo "Sorry, there the username $username is already taken.<br>";
echo "<a href=register.html>Try again</a>";
exit; 
} else {

// insert the data
$insert = mysql_query("insert into _test values ('NULL', '".$_POST['username']."','".$_POST['password']."')") or die("Could not insert data because ".mysql_error());

// print a success message
echo "Your user account has been created!<br>"; 
echo "Now you can <a href=login.html>log in</a>"; 
}

&GT;

0 个答案:

没有答案