【发布时间】:2017-12-09 08:27:29
【问题描述】:
我正在尝试将 html 文件中的数据插入到我的数据库“客户”中
但是,我能够连接到数据库,但无法将 html 文件中的数据插入到我的数据库中
截图error
备注:
- 我没有为 phpmyadmin 设置密码,只是将用户名设置为“root”
- 所有文件都存储在同一个文件夹中(C:\wamp64\www)
customers.html
<!DOCTYPE html>
<html>
<head>
<title>customers</title>
</head>
<body>
<center><form action="SignUp.php" method="POST">
<input type="text" name="id" placeholder="customer id"><br>
<input type="text" name="firstname" placeholder="firstname"><br>
<input type="text" name="orderno" placeholder="order no"> <br>
<input type="text" name="city" placeholder="city"><br>
<input type="text" name="price" placeholder="product price"><br>
<button type="submit">order</button>
</form>
</center>
</body>
</html>
SignUp.php
<?php
include 'db.php';
$sql= "INSERT INTO customers (id,firstname,orderno,city,price)
VALUES ('345','username','979','city','4465')";
if($result=mysql_query($sql)==true)
echo "data inserted successfully";
else
echo "failed to insert data";
?>
db.php
<?php
$conn=mysqli_connect("localhost","root","","customers");
if(!$conn){
die("connection failed : " .mysqli_connect_error());
}
else{
echo "connection created successfully"."<br>";
}
?>
【问题讨论】:
-
您将
mysqli_*函数与mysql_组合在一起,它们并不相同。 -
你试过用谷歌搜索消息吗? mysql_* 已弃用,因此不要编写包含它的代码,也不要混合使用 mysql* 和 mysqli*。 “访问被拒绝”看起来使用您输入的凭据无法访问
-
我没有设置任何凭据密码为空且用户名为“root”