php向mysql写入数据失败,弄了好久都弄不出来。看看问题在哪
html:代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.min.css"/>
<title></title>
</head>
<body>
<form action="formData.php" method="get">
<label>姓名:</label><input type="text" name="user"/><br>
<label>密码:</label><input type="password" name="pass"><br>
<input type="submit" value="注册"/>
</form>
</body>
</html>
php:代码:
$user=$_GET['user'];
$pass=$_GET['pass'];
$db_host="localhost";
$db_name="root";
$db_pwd="";
$link=mysqli_connect($db_host,$db_name,$db_pwd) ;//2.判断是否成功
if ($link){
echo"success";
}else {
echo"fail";}
//3.设置字符集
mysqli_set_charset($link,"utf8");
//4.选择数据库
mysqli_select_db($link,"lhy");
$sql = "use lhy;";
$sql += "INSERT into ifm(name,password) values ('$user','$pass');";
if ($link->query($sql) === TRUE) {
echo"新记录插入成功";
} else {
echo " Error:".$sql."
".$link->error;
}
数据库:
运行结果: