提问者:小点点

使用php在mysql数据库中添加用户名、电子邮件和密码时出错


我正在尝试使用PHP注册用户。不知怎么的,唯一放进去的就是身份证。介意给我点小费吗?

 <?php
error_reporting(0);

require_once "php/connect.php";
$username = $_POST ['username'];
$useremail = $_POST['useremail'];
$userpwd = $_POST ['userpwd'];
$userpwd2 = $_POST['userpwd2'];



    try {
        $statement = $dbconnection->prepare("INSERT INTO `tbl_Nutzerdaten` (userid, username, useremail, userpwd) VALUES (null , '$username', '$useremail', '$userpwd')");
        $result = $statement->execute();
        $fetch = $statement->fetch();

    } catch (PDOException $e) {
        echo "Fehler:" . $e->getMessage();

    }

?>

这就是我的insert.php的样子。我一直在努力改变我的体形,但还是没有成功。数据库有一个表:“tbl_nutzerdaten”,其中包含列userid、username、useremail和userpwd。但是我不能添加任何东西,除了ID。

<!DOCTYPE html>
<html lang="de">
<head>
    <title>Registrierung</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="css/bootstrap.min.css" rel="stylesheet" >
    <script src="js/bootstrap.bundle.min.js" ></script>
    <?php
    error_reporting(0);
    require_once "insert.php";
    ?>
</head>
<body>
<div class="container bg-transparent border-0">
    <div class="row">
        <div class="col-sm-9 col-md-7 col-lg-5 mx-auto border-0">
            <div class="img-thumbnail my-5 border-0">
                <img src="bilder/htl logo.png"></img>
                <div class="card card-signin my-5 border-0">
                    <div class="card-body border-0">

                        <form class="form-signin form-control border-0" action="#" method="post">
                          <div class="form-label-group">
                              <h1 class="text-center">Registrierung</h1>
                               <label for="username">Benutzername</label>
                               <input type="text" id="username" class="form-control text-center" placeholder="Benutzername" required autofocus>
                              <div class="form-label-group">
                              <label for="useremail">Email</label>
                              <input type="email" id="useremail" class="form-control text-center" placeholder="Email" required autofocus>
                              </div>
                         </div>

                            <div class="form-label-group">
                                <label for="Passwort">Passwort</label>
                                <input type="password" id="userpwd" class="form-control text-center" placeholder="Passwort" required>

                            </div>
                            <div class="form-label-group">
                                <label for="Passwort2">Passwort bestätigen</label>
                                <input type="password" id="userpwd2" class="form-control text-center" placeholder="Passwort bestätigen" required>

                            </div>


                            <div class="custom-control custom-checkbox mb-3">
                             <input type="checkbox" class="custom-control-input" id="pwcheck">
                             <label class="custom-control-label" for="pwcheck">Password merken?</label>
                            </div>
                          <button class="btn btn-lg btn-primary btn-block text-uppercase " type="submit">Registrieren</button>


                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

这就是我使用的形式。

每次填写表单时,我在数据库中看到的唯一东西是一个ID和空值。我真的很感激你的帮助。


共1个答案

匿名用户

要将数据发送到特定的PHP文件,您必须定义…

在HTML页面中的form标记中,action属性定义了发送信息的file.php路径。

例如: