如果按下提交按钮,我想将数据插入到我的表中。到目前为止我有这个

时间:2016-06-18 14:16:59

标签: php html mysqli

<!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按钮时如何插入数据。

1 个答案:

答案 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();
}
?>

我的数据库结构:     enter image description here