input框localid输入值后,通过Ajax调取mySQL自动回显数据到另外两个username和team里,
然后提交数据到数据库。
mysql表:demo
DROP TABLE IF EXISTS `demo`;
CREATE TABLE `demo` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`localid` varchar(255) DEFAULT NULL,
`username` varchar(255) DEFAULT NULL,
`team` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `demo` VALUES (1,'JC','JJCC','23'),(2,'TB','TTBB','32'),(3,'YC','YYCC','44');
链接数据库,conn.php
<?php
// 创建连接
$conn = new mysqli("localhost", "root", "root", "study", 3306);
$conn->set_charset("utf8");
// 检测连接
if ($conn->connect_error) {
die("数据库连接失败: " . $conn->connect_error);
}
?>
HTML输入页面:demo.html
需要ajax的赋值代码及submit的代码
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
</head>
<body>
<form>
<input type="text" name="localid">
<input type="text" name="username">
<input type="text" name="team">
<button>提交</button>
</form>
<script>
//ajax根据input框的localid从数据库获取另外两个值并自动赋值到username和team框
url:demo_ajax.php//使用php后台获取数据
</script>
</body>
</html>