<!DOCTYPE html>
<html>
<head>
<title>Sign up page</title>
</head>
<body>
<form method="get" action="signup_redirect.php">
username: <input type="text" name="username" placeholder="username"><br>
Password: <input type="password" name="password" placeholder="password"><br>
<input type="submit" value="Create Account">
</form>
<?php
if(isset($_POST['submit'])) {
$dbCon = mysqli_connect("localhost", "root", "", "test");
if (mysqli_connect_errno()) {
echo "Failed to connect" .mysqli_connect_error();
}
?>
</body>
</html>
所以我将此表单连接到我的数据库,但是我不确定在按下SUBMIT
按钮时如何插入数据。
答案 0 :(得分:0)
这里以html格式和php中使用不同的方法。在HTML中你有 GET ,在PHP中你有 POST 检查。对于身份验证更好地使用POST方法所以我们可以改变你的代码:
<强> HTML 强>:
<form method="post" action="signup_redirect.php">
username: <input type="text" name="username" placeholder="username"><br>
Password: <input type="password" name="password" placeholder="password"><br>
<input type="submit" value="Create Account">
</form>
PHP :
<?php
if(isset($_POST['submit'])) {
$dbCon = mysqli_connect("localhost", "root", "", "test");
if (mysqli_connect_errno()) {
echo "Failed to connect" .mysqli_connect_error();
}
?>
我的数据库结构: