PHP连接错误;不允许连接到MySQL服务器

问题描述 投票:2回答:2

我正在尝试创建一个注册页面,它将信息添加到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

提前致谢。

php html sql registration
2个回答
5
投票

如果您的mysql数据库不在同一服务器(localhost)上,则需要从远程服务器为其服务器的mysql用户/数据库提供访问权限。有关可能对您有所帮助的一些步骤,请参阅此文章听起来它可能是遥远的。

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


0
投票

创建新的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();
}
© www.soinside.com 2019 - 2024. All rights reserved.