【问题标题】:PHP Connection Error; Not allowed to connect to MySQL ServerPHP 连接错误;不允许连接到 MySQL 服务器
【发布时间】:2013-06-27 11:51:20
【问题描述】:

我正在尝试创建一个注册页面,将信息添加到 SQL 表中。这是我执行此操作的 PHP 代码...谁能告诉我这是什么错误?

<?php
$con=mysqli_connect("Correct Website is here","Correct Username","Correct Pass","Correct DB");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$DBsql = mysql_query("SELECT username, email from Profiles");
$sql = mysql_fetch_array($DBsql);

if(!($_POST['username'] == $sql['username']) && ($_POST['email'] == $sql['email'])) {
 if ($_POST['password'] == $_POST['password2']){      
  $sql="INSERT INTO Profiles (firstName, lastName, username, email, password, region, group, verified)
  VALUES
  ('$_POST[firstname]','$_POST[lastname]','$_POST[username]','$_POST[email]','$_POST[password]','$_POST[region]','member','no')";
 }else{
     echo '<script type="text/javascript">'
   , 'window.alert("The passwords do not match.")'
   , '</script>';
 }
} else {
    echo '<script type="text/javascript">'
   , 'window.alert("That username or email is already in use.")'
   , '</script>';
}

 mysqli_close($con);
?>

它给出了这些错误:

Warning: mysqli_connect() [function.mysqli-connect]: (HY000/1130): Host '31.170.161.96' is not allowed to connect to this MySQL server in /home/a5349216/public_html/register.php on line 2

Failed to connect to MySQL: Host 'ip' is not allowed to connect to this MySQL server

Warning: mysql_query() [function.mysql-query]: Access denied for user 'username'@'localhost' (using password: NO) in /home/username/public_html/register.php on line 8

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/username/public_html/register.php on line 8

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/username/public_html/register.php on line 9

Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in /home/username/public_html/register.php on line 27

【问题讨论】:

  • 请确保您的帖子中没有发布实际的数据库主机名和用户名。 “31.170.161.96”和“a5349216”

标签: php html sql registration


【解决方案1】:

如果您的 mysql 数据库不在同一台服务器(本地主机)上,您需要从远程服务器为您的服务器的该 mysql 用户/数据库授予它访问权限。有关可能对您有所帮助的一些步骤,请参阅本文。听起来可能很遥远。

https://support.rackspace.com/how-to/mysql-connect-to-your-database-remotely/

【讨论】:

  • 链接失效
  • @lmcarreiro 所以我对他们更改链接表示反对?我回答了 OP 的问题,即告诉他错误是什么意思。该链接是一个奖励。反正它是固定的。
  • 您告诉他该做什么,而不是如何...
  • @lmcarreiro 哈哈,这个网站总是给人们一个准确的答案。有时它会引导你找到答案。但他问what 错误是Can anyone tell me what the error with this is 而不是如何修复它。 :) 无论如何,新链接应该会有所帮助
【解决方案2】:

创建新的 php 文件,只需使用以下语法进行测试。让我知道你的错误。

$con=mysqli_connect("Correct Website is here","Correct Username","Correct Pass","Correct DB");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

【讨论】:

  • 警告:mysqli_connect() [function.mysqli-connect]: (HY000/1130): Host 'ip' is not allowed to connect to this MySQL server in /home/username/public_html/register. php on line 2 Failed to connect to MySQL: Host 'ip' is not allowed to connect to this MySQL server
  • 很明显,这是与权限相关的问题。联系托管服务提供商
猜你喜欢
  • 2021-06-23
  • 2014-01-17
  • 1970-01-01
  • 2013-03-31
  • 2013-10-09
  • 2015-04-22
  • 2013-10-17
  • 2012-11-12
  • 1970-01-01
相关资源
最近更新 更多