php - 注册成功但数据库中没有数据

标签 php mysql

当我使用代码插入数据时,我收到一条消息,表明您注册成功,即数据已插入表中,但我无法在本地数据库中找到数据。

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Registration</title>
    <link rel="stylesheet" href="css/style.css" />
</head>
<body>
    <?php
    require('db.php');

    if (isset($_REQUEST['username'])) {
        $username = "username";
        $email = "email";
        $password = "password";
        $trn_date = date("Y-m-d H:i:s");
        $query = "INSERT into `users` (username, password, email, trn_date)
        VALUES ('$username', '".md5($password)."', '$email', '$trn_date')";
        $result = mysqli_query($con, $query);
        if($result) {
            echo "<div class='form'>
            <h3>You are registered successfully.</h3>
            <br/>Click here to <a href='login.php'>Login</a></div>";
        }
    } else {
        ?>
        <div class="form">
            <h1>Registration</h1>
            <form name="registration" action="" method="post">
                <input type="text" name="username" placeholder="Username" required />
                <input type="email" name="email" placeholder="Email" required />
                <input type="password" name="password" placeholder="Password" required />
                <input type="submit" name="submit" value="Register" />
            </form>
        </div>
        <?php }
        ?>
</body>
</html>

最佳答案

你必须先了解更多有关 php 的知识,然后才能提问。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Registration</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<?php
require('db.php');

if (isset($_POST['username'])){
$username= $_POST["username"];
$email = $_POST["email"];
$password = $_POST["password"];
$trn_date = date("Y-m-d H:i:s");
$query = "INSERT into `users` (username, password, email, trn_date)
VALUES ('$username', '".md5($password)."', '$email', '$trn_date')";
    $result = mysqli_query($con,$query);


    if($result){
        echo "<div class='form'>
<h3>You are registered successfully.</h3>
<br/>Click here to <a href='login.php'>Login</a></div>";
    }
}else{
?>
<div class="form">
<h1>Registration</h1>
<form name="registration" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="username" placeholder="Username" required />
<input type="email" name="email" placeholder="Email" required />
<input type="password" name="password" placeholder="Password" required />
<input type="submit" name="submit" value="Register" />
</form>
</div>
<?php } ?>
</body>
</html>

关于php - 注册成功但数据库中没有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40361656/

相关文章:

javascript - 从 PHP 返回二维数组到 JavaScript

php - 更改 WooCommerce 短代码输出中的标记

javascript - 如何在加载时显示进度条,使用ajax

javascript - Ajax 调用不断失败,但没有错误

php - 为什么在确定 PHP 准备语句中 select 查询返回的行数时存储结果集?

php - CakePHP HABTM 条件

android - 如何使位置自动递增并避免在 ListView 中得到重复的结果?

PHP 如何实例化一个内部类

mysql - 不同列的不同值

mysql - 更改表错误