douxue7196 2013-06-30 01:14
浏览 62
已采纳

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

I am trying to make a registration page where it adds the information to a SQL Table. Here is my PHP code to do this... Can anyone tell me what the error with this is?

<?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);
?>

It's giving these errors:

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

Thanks in advanced.

  • 写回答

2条回答 默认 最新

  • dsaxw4201 2013-06-30 01:19
    关注

    If your mysql database is not on the same server(localhost) you need to give it access from a remote server for that mysql user/database for your server. See this article for some steps that might help you. It sounds like it might be remote.

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝