簡體   English   中英

PHP + MYSQL不會插入數據庫

[英]PHP+MYSQL Won't Insert Into Database

好的,在我的注冊頁面上,它只是刷新。 我的登錄名可以讓您登錄,但我的注冊只是重新加載頁面。

另外,我正在嘗試在您注冊時在上面添加交易代碼

這是我的注冊頁面代碼

<?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>

當我單擊提交按鈕時,它只會刷新頁面。

您需要將表單action =“”設置到注冊頁面。 您當前的空白操作使其提交到表單所在的頁面,而不是您的注冊代碼所在的頁面。 因此,它只是刷新當前頁面。

使用注冊頁面代碼的文件名設置action =“”

例如:

如果您有兩個不同的文件,一個用於表單提交,另一個用於注冊頁面代碼,文件名為“ abc.php”

在您的表單Submit action =“ abc.php”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM