本文介绍了PHP连接错误;不允许连接到MySQL服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个注册页面,将信息添加到SQL Table中。这是我的PHP代码来做到这一点...任何人都可以告诉我这是什么错误?

 <?php 
$ con = mysqli_connect(正确的网站在这里,正确的用户名,正确的通行证,正确的数据库);
if(mysqli_connect_errno())
{
echo无法连接到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 =插入配置文件(firstName,lastName,username,email,password,region ,组,已验证)
VALUES
('$ _POST [firstname]','$ _ POST [lastname]','$ _ POST [用户名]','$ _ POST [email]','$ _ POST [密码], '$ _ POST [区域]', '部件', '无');
} else {
echo'< script type =text / javascript>'
,'window.alert(密码不匹配)'
,'< / script>';
$ b} else {
echo'< script type =text / javascript>'
',window.alert(该用户名或电子邮件已被使用。)'
,'< / script>';
}

mysqli_close($ con);
?>

这是错误提示:

<$ p $警告:mysqli_connect()[function.mysqli-connect]:(HY000 / 1130):主机'31.170.161.96'不允许连接到这个MySQL服务器的/ home / a5349216 / public_html /第二行的register.php

无法连接到MySQL:主机'ip'不允许连接到这个MySQL服务器

警告:mysql_query()[function.mysql -query]:在第8行的/home/username/public_html/register.php中访问被用户'用户名'@'localhost'拒绝(使用密码:NO)

警告:mysql_query()[function .mysql-query]:无法在第8行的/home/username/public_html/register.php中建立到服务器的链接

警告:mysql_fetch_array():提供的参数不是有效的MySQL结果资源位于第9行的/home/username/public_html/register.php上

警告:mysqli_close()期望参数1为mysqli,布尔在/home/username/public_html/register.php中给出o第27行

感谢您的进一步支持。




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.

解决方案

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.

http://www.rackspace.com/knowledge_center/article/mysql-connect-to-your-database-remotely

这篇关于PHP连接错误;不允许连接到MySQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 21:35