将html数据传递到数据库

首先是一个用户可见的html网页

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>login</title>
</head>
<body>
<form action="result.php" method="post">
qq号码: <input type="text" name="username" ><br>
qq密码: <input type="text" name="password" ><br>
<input type="submit" value="登录">
</form>
</body>
</html>


点击登录后,将数据post给result.php

result.php

<?php header("Content-type:text/html;charset=utf-8"); //数据类型是utf-8 不加入可能会乱码 $serverName = "localhost";//服务器ip $username = "root";//mysql用户名称 $password = "123456";//密码 $dataBase = "yunhu";//数据库名称 $conn = new mysqli($serverName, $username, $password,$dataBase); if($conn->connect_error) {//连接失败 echo "对不起,服务器未响应"; echo "<br>"; } //数据库数据编码格式 $sql = "SET NAMES UTF8"; if($conn->query($sql) === true) { //echo "set success<br>"; } else { echo "set fail<br>"; } $username = $_POST['username']; $password = $_POST['password']; //echo $username." ".$password; $result = array(); if($username == "") { $result["result"] = "false"; } else { $add = $conn->prepare("INSERT INTO userInformation(username,password) VALUES(?,?)"); $add->bind_param("ss", $username,$password); $stmt = $conn->prepare("SELECT * FROM userInformation WHERE username=?"); $stmt->bind_param("s", $username); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($id); if($stmt->fetch()) { $result["result"] = "false"; } else { $add->execute(); $result["result"] = "true"; } } //echo json_encode($result); ?>
全部评论

相关推荐

11-11 16:40
已编辑
门头沟学院 人工智能
不知道怎么取名字_:这个有点不合理了,相当于已经毕业了,但还是没转正,这不就是白嫖
点赞 评论 收藏
分享
12-16 22:01
门头沟学院 Java
程序员牛肉:可以的,简历没毛病了。 虽然还是偏向同质化,不过学历不错。后续我觉得重心放到刷实习+摆脱同质化问题上
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务