用户拒绝访问 - (使用密码:否)

时间:2015-10-17 13:09:24

标签: php html connection

您好我试图连接到我的数据库以使用我的注册表格,但我没有运气。当我运行connection.php时,它会显示以下消息:拒绝访问用户'' 10.246.64.24' (使用密码:否)

任何提示非常感谢:)

connection.php:

<?php
$servername = "c3438525.co.uk.mysql";
$username = "c3438525_co_uk";
$password = "password";
ob_start();
$con=mysqli_connect("c3438525.co.uk.mysql", "c3438525_co_uk", "password", "c3438525_co_uk");

if ($con->connect_error)
{
    die("Connection failed: " . $con7>connect_error);
}
echo "Connected Successfully";
mysql_select_db( 'c3438525_co_uk' ) or die(mysql_error());
?>

和我的 registrationsubmit.php

<font face="ClearSans-Thin">
<font color="lightgray">

<?php

include 'registrationform.php';
include 'connection.php';
?>

<?php
if (isset($_POST['regsubmit'])) {
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $username = $_POST['username'];
    $password = $_POST['password'];
    //Insert into database the values entered in the registration form.
    $query = "INSERT INTO users (FirstName, LastName, Username, Password) VALUES ("$firstname","$lastname", "$username", "$password")"  
}
  Echo "Registration Successful - Press the Home button to return to the homepage.";

}
?>
</center>   

1 个答案:

答案 0 :(得分:0)

mysqli_connect(...
mysql_select_db('c3438525_co_uk'

您正在将mysqli与旧的mysql扩展中的函数混合使用。这不起作用。
由于没有通过mysql_connect建立连接,mysql扩展尝试在调用mysql_select_db时建立默认连接。因此user ''@'10.246.64.24' (using password: NO)消息 删除所有mysql_ *函数并仅使用mysqli版本。

顺便说一下:在你的第二个脚本(发布中)中,查询实际上并没有发送到mysql服务器。但它可能不是真正的&#34;脚本无论如何,因为它会导致解析错误,因为dobule引用的字符串文字中的双引号。

但是当你正在阅读时,请同时阅读http://docs.php.net/security.database.sql-injection