用的是html和php的混合代码,适用于初学者,了解前后端简单的逻辑
<form method="post" class="zhuce" action="mysql4.php">
<div class="name">
用户名:<input type="text" name="uname">
</div>
<div class="name">
密码:<input type="password" name="upwd">
</div>
<input type="submit" value="登录">
</form>
<?php
?>
<?php
?>
<?php
?>
<?php
$servername = "localhost";
$username = "root";
$password = "123456";
$dbname = "YongHuBiao";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
$stmt = $conn->prepare("INSERT INTO yonghubiao (uname, password) VALUES (?, ?)");
$stmt->bind_param("ss", $uname, $password);
$uname = $_POST["uname"];
$password = $_POST["upwd"];
$stmt->execute();
$stmt->close();
$conn->close();
echo "新记录插入成功666";
?>
最后的echo那个语句不知道该怎么让它在数据提交后才显示
|