PHP + MYSQL不会插入数据库

时间:2015-12-07 05:53:08

标签: php mysqli pdo

在我的注册页面上确定它只是刷新。我的登录让您登录,但我的注册只是重新加载页面。

此外,我在注册

时尝试在其上添加交易代码

这是我的注册页码

<?php
error_reporting(0);
ob_start();
session_start();

// Include DB
require('inc/Database.php');
$db = new Database();
$pageName = "Register";

// Include user class
include('inc/user.php');
$user = new User($db);

if(isset($_POST['submit'])){

            $_POST['username'] = preg_replace('/[^A-Za-z0-9\-]/', '', $_POST['username']);
            $username = $_POST['username'];
            // $password = $_POST['password'];
            $password = hash("sha256", $_POST['password']);
            $count = $db->count('SELECT COUNT(username) FROM members WHERE username = ?', array($username));

            if (!$count) {
                $activation = md5(uniqid(rand(),true));
                $result = $db->insert('INSERT INTO members (username,transaction,ownerIP,signupDate,password,email,active) VALUES (?, ?, NOW(), ?, ?, ?, ?)', array($username, $transaction, $ownerIP, $password, $_POST['email'], $activation));
                if ($result) {
                    $to = $_POST['email'];
                    $subject = "Welcome to ShareTracks!";
                    $body = "Thank you for registering at ShareTracks! The number one music app and community!\n\nActivate your account by simply clicking on the link below:\n\n http://sharetracks.net/activate.php?user=$username&code=$activation";
                    $additionalheaders = "From: accounts@sharetracks.net\r\n";
                    $additionalheaders .= "Reply-To: accounts@sharetracks.net";
                    mail($to, $subject, $body, $additionalheaders);
                    header('Location: login.php?action=joined');
                } else {
                    header('Location register.php?error=data');
                }
            } else {
                header('Location: register.php?error=taken');
            }
}
?>

这是我的注册html表单:

        <div class="account-form">
            <form class="form-signup" role="form" method="post" action="" autocomplete="off">
                <h3><strong>Create</strong> your account</h3>
          <?php if($_GET['error'] == 'data') {
            echo '<center><div class="alert alert-info"><i class="fa fa-warning"></i> It seems you have entered invalid data, please sign up again using valid characters [A-Z/1-9].</div></center>'; 
          } ?>

          <?php if($_GET['error'] == 'taken') {
            echo '<center><div class="alert alert-info"><i class="fa fa-warning"></i> The username you have chosen is already taken. Try another one.</div></center>'; 
          } ?>                  
                <div class="append-icon">
                    <input type="text" name="username" id="username" placeholder="Username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" class="form-control form-white username" required>
                    <i class="icon-user"></i>
                </div>
                <div class="append-icon">
                    <input type="email" name="email" id="email" class="form-control form-white email" placeholder="Email Address" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" required>
                    <i class="icon-envelope"></i>
                </div>
                <div class="append-icon m-b-10">
                    <input type="password" name="password" id="password" class="form-control form-white password" placeholder="Password" required>
                    <i class="icon-lock"></i>
                </div>
                <div class="append-icon m-b-20">
                    <input type="password" name="passwordConfirm" id="passwordConfirm" class="form-control form-white password2" placeholder="Confirm Password" required>
                    <i class="icon-lock"></i>
                </div>
                <div class="append-icon m-b-20">
                    <input type="text" name="transaction" id="transaction" class="form-control form-white transaction" placeholder="PayPal Transaction" required>
                    <i class="fa fa-usd"></i>
                </div>                  
                <div class="terms option-group">
                    <label  for="terms" class="m-t-10">
                    <input type="checkbox" name="terms" id="terms" data-checkbox="icheckbox_square-blue" required/>
                    I agree with terms and conditions
                    </label>  
                </div>
                <div class="m-t-20">
                    <button name="submit" type="submit" class="btn btn-lg btn-dark btn-rounded" data-style="expand-left">Register</button>
                </div>
            </form>
            <div class="form-footer">
                <div class="clearfix">
                    <p class="new-here"><a href="login.php">Already have an account? Sign In</a></p>
                </div>
            </div>
        </div>
    </div>

当我点击提交按钮时,它只刷新页面。

2 个答案:

答案 0 :(得分:0)

您需要设置表单操作=&#34;&#34;到你的注册页面。您当前的空白操作会将其提交到您的表单所在的页面,而不是您的注册码所在的页面。所以它只刷新当前页面。

答案 1 :(得分:-1)

使用注册页面代码的文件名设置action =“”

示例:

如果您有两个不同的文件,一个用于表单提交,另一个用于注册页面代码,文件名为“abc.php”

在表单提交操作=“abc.php”