<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>testmysql</title>
</head>
<body>
<form action = 'loginmysql.php' method="post">
分数: <input type="text" name="right" ><br>
<button type="submit">提交到mysql</button>
</form>
</body>
</html>
<?php $serverName = "localhost"; $username = "root"; $password = "password"; $dbname = "2048"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("连接失败: " . $conn->connect_error); } $rightscore= $_POST['right']; $sql = "INSERT INTO 2048score (score) VALUES ($rightscore)"; if ($conn->query($sql) === TRUE) { echo "新记录插入成功"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); ?>