我的任务是关于与xampp服务器的PHP连接,它没有连接并给我erroe [关闭]

Kindly show me the error in my code i am trying to connect the sign in form with database using php but i am getting these errors:

Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\MyProject\php\signin.php on line 9

Notice: Trying to get property of non-object in C:\xampp\htdocs\MyProject\php\signin.php on line 11

Fatal error: Uncaught Error: Call to a member function query() on boolean in C:\xampp\htdocs\MyProject\php\signin.php:17 Stack trace: #0 {main} thrown in C:\xampp\htdocs\MyProject\php\signin.php on line 17

<?php

$servername = "localhost";
$username = "root";
$password="";
$dbname = "myproject";

// Create connection
$conn = mysqli_connect($servername,$username,$password,$dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "INSERT INTO sign_in (username,password)";

if ($conn->query($sql) === TRUE) {
    echo "New record inserted successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}


$conn->close();

?>
douchengfei3985
douchengfei3985 MySQLERROR1045(28000)可能重复:用户'账单'@'localhost'拒绝访问(使用密码:YES)
2 年多之前 回复
dony39517
dony39517 访问被拒绝的不清楚?
2 年多之前 回复

3个回答

You are getting this ERROR because of your is mixed up with mysqli_* functions and PDO code.

Methods of both PDO connection and mysqli_* are different.

Here is your error. ******Here is your error*****

$sql = "INSERT INTO sign_in (username,password)";

if ($conn->query($sql) === TRUE) { //ERROR line
    echo "New record inserted successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

You have use function mysqli_query() instead of accessing member function of $conn, just take below correct example.

// Perform queries 
mysqli_query($conn,"SELECT * FROM Persons");
mysqli_query($conn,"INSERT INTO Persons (FirstName,LastName,Age) VALUES ('Glenn','Quagmire',33)");

mysqli_close($conn);

Hope you get the point and will help you..

drf21989
drf21989 “你得到这个错误是因为你和mysqli_函数和PDO代码混在一起.PDO连接和mysqli_ *的方法都不一样。”* - 嗯? 你在哪里看到混合api? 应该从答案中解脱出来。
2 年多之前 回复
doupu2722
doupu2722 或者他们可以用$ conn = new mysqli(...)替换$ conn = mysqli_connect(...)
2 年多之前 回复



root mysql帐户上必须有一个密码,你不在这里提供:</ p>

   $ password =“”; 
</ code> </ pre>

错误的其他部分直接导致这种情况,$ conn成为布尔值,而不是mysqli_connect的对象 ()不成功(失败时返回false)。</ p>
</ div>

展开原文

原文

There must be a password on root mysql account that you're not providing here:

$password="";

Other parts of the error is a direct consequence of this, $conn became a boolean and not an object as the mysqli_connect() is unsuccessful (it gives back false on failure).



您的查询不正确,因为没有给出插入的值。 它应如下所示:</ p>

  $ sql =“INSERT INTO sign_in(用户名,密码)VALUES($ username,$ password)”; 
</ code> </ pre>
</ div>

展开原文

原文

Your query is not correct, since no values where given to insert. It should look like this:

$sql = "INSERT INTO sign_in (username,password) VALUES ($username,$password)";

douluo6626
douluo6626 VALUES($ username,$ password) - 你知道你在这里写的是什么吗? 你确实意识到那些不是整数,而是字符串,需要正确处理。
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐