簡體   English   中英

注冊表php

[英]registration form php

我正在一個網頁上顯示有關繪畫的信息。

我創建了一個名為“ register.php”的網頁,在該網頁中,用戶在下達繪畫訂單之前必須先填寫注冊表。 然后出現一個名為“ details.php”的頁面,要求用戶輸入更多詳細信息。 最后,顯示一個名為“ vieworders.php”的頁面,其中顯示了訂單的詳細信息和繪畫狀態。

問題1:我創建了一個名為“用戶”的數據庫,該數據庫具有以下字段:“ id(主鍵自動遞增),用戶名,電子郵件和密碼。為什么當用戶提交注冊表格時,數據沒有顯示在我的數據庫中? ?

問題2:用戶如何能夠隨時回來查看繪畫狀態?

這是我的代碼:

register.php

<?php
session_start();

$id = $_POST["accept"];
$paintingname = $_POST["accept1"];

$host = "xx";
$user = "xx";
$pass= "xx";
$dbname = "xx";
$conn = new mysqli($host,$user,$pass, $dbname );

$_SESSION['id'] = $id;
$_SESSION['paintingname'] = $paintingname;

if ($conn->connect_error) {
    die("Connection failed : ".$conn->connect_error); //fixme
}

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

        $username = isset($_POST["username"]) ? $conn->real_escape_string($_POST["username"]) : "";
        $email = isset($_POST["email"]) ? $conn->real_escape_string($_POST["email"]) : "";
        $password = isset($_POST["password"]) ? $conn->real_escape_string($_POST["password"]) : "";
        $password2 = isset($_POST["password2"]) ? $conn->real_escape_string($_POST["password2"]) : "";


        if ($password_1 != $password_2) {
            array_push($errors, "The two passwords do not match");
        }

        // first check the database to make sure
        // a user does not already exist with the same username and/or email
        $user_check_query = "SELECT * FROM users WHERE username='$username' OR email='$email' LIMIT 1";
        $result = mysqli_query($conn, $user_check_query);
        $user1 = mysqli_fetch_assoc($result);

        if ($user1) { // if user exists
            if ($user1['username'] === $username) {
                array_push($errors, "Username already exists");
            }

            if ($user1['email'] === $email) {
                array_push($errors, "email already exists");
            }
        }

        // Finally, register user if there are no errors in the form
        if (count($errors) == 0) {
            $password = md5($password_1);//encrypt the password before saving in the database

            $query = "INSERT INTO users(username, email, password) 
                VALUES('$username', '$email', '$password')";
            mysqli_query($db, $query);

        }
    }

?>

<html>
<head>
    <title>Registration system PHP and MySQL</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="header">
    <h2>Register</h2>
</div>

<form method="post" action="confirm.php">

    <div class="input-group">
        <label>Username</label>
        <input type="text" name="username" required />
    </div>
    <div class="input-group">
        <label>Email</label>
        <input type="email" name="email" required />
    </div>
    <div class="input-group">
        <label>Password</label>
        <input type="password" name="password_1" required />
    </div>
    <div class="input-group">
        <label>Confirm password</label>
        <input type="password" name="password_2" required />
    </div>
    <div class="input-group">
        <button type="submit" class="btn" name="reg_user" >Register</button>
    </div>
    <p>
        Already a member? <a href="login.php">Sign in</a>
    </p>
</form>
</body>
</html>

details.php

<html>
<head>
    <title>Table with database</title>
    <style type ="text/css">
        table {
            border: 2px solid red;
            background-colour: #FFC;
        }
        th {
            border-bottom: 5px solid #000;
        }
        td {
            border-bottom: 2px solid #666;
        }
    </style>


</head>
<body>

<?php
session_start();
$servername = "xx";
$username = "xx";
$password= "xx";
$dbname = "xx";
$conn = new mysqli($servername,$username,$password, $dbname );


$id = $_POST["accept"];

if ($conn->connect_error) {
    die("Connection failed : ".$conn->connect_error); //fixme
}
$sql=  "SELECT * FROM `listart` where id =".$id;
$result=$conn->query($sql);


if ($result->num_rows > 0) {
    echo "<table>\n";
    echo "<tr>";
    echo "<th>ID</th>";
    echo "<th>Image</th>";
    echo "<th>Description</th>";
    echo "<th>Date of completion</th>";
    echo "<th>Painting Name</th>";
    echo "<th>Height</th>";
    echo "<th>Width</th>";
    echo "<th>Price</th>";

    echo "</tr>";
    while ($row = mysqli_fetch_array($result)) {

        echo "<tr>\n";
        echo "<td>".$row["id"]."</td>\n";
        echo "<td>"; echo ' <img src= "data:image/jpeg;base64,'.base64_encode($row['image']).'" height = "200 width = "200"/>'; echo "</td>";
        echo "<td>".$row["description"]."</td>\n";
        echo "<td>".$row["Dateofcompletion"]."</td>\n";
        echo "<td>".$row["pname"]."</td>\n";
        echo "<td>".$row["height"]." mm "."</td>\n";
        echo "<td>".$row["width"]." mm "."</td>\n";
        echo "<td>"."£ ".$row["price"]."</td>\n";
        echo "<td><form action='register.php' method='POST'><input type='hidden' name='accept' value='".$row["id"]."'/><input type='hidden' name='accept1' value='".$row["pname"]."'/> <input type='submit' name='submit-btn' value='Order'><button type='button' onclick=\"history.back();\">Back</button></form></td>";
        echo "</tr>\n";

    }
    echo "</table>\n";
}

$conn->close();
?>


</body>
</html>

vieworders.php

<html>
<head>
    <title>Table with database</title>
    <style type ="text/css">
        table {
            border: 2px solid red;
            background-colour: #FFC;
        }
        th {
            border-bottom: 5px solid #000;
        }
        td {
            border-bottom: 2px solid #666;
        }
    </style>


</head>
<body>
<h2>Here is a table with your orders!</h2>
<div>

<?php
session_start();
$servername = "xx";
$username = "xx";
$password= "xx";
$dbname = "xx";
$conn = new mysqli($servername,$username,$password, $dbname );


$id =  $_SESSION['id'];
$paintingname =  $_SESSION['paintingname'];


    if (isset($_POST['submit'])) {
        $uname = isset($_POST["uname"]) ? $conn -> real_escape_string($_POST["uname"]):"";
        $email = isset($_POST["email"]) ? $conn -> real_escape_string($_POST["email"]):"";
        $paddress = isset($_POST["padd"]) ? $conn ->  real_escape_string($_POST["padd"]):"";
        $phonenumber = isset($_POST["phonenumber"]) ? $conn -> real_escape_string($_POST["phonenumber"]):"";
    }


if ($conn->connect_error) {
    die("Connection failed : ".$conn->connect_error); //fixme
}


$sql = "INSERT INTO vieworders(id,paintingname,username,email,postalcode,phonenumber) VALUES
    ('$id','$paintingname','$uname','$email','$paddress','$phonenumber');";

//echo "<p><b>$sql</b></p>";

if ($conn->query($sql) == TRUE) {
    echo "<p> Insert successful </p>";
}
else {
    die("error on insert".$conn->error);
}


$sql  = "SELECT * FROM `vieworders`";
$result1=$conn->query($sql);


if ($result1->num_rows > 0) {
    echo "<table>\n";
    echo "<tr>";
    echo "<th>ID</th>";
    echo "<th>Painting Name</th>";
    echo "<th>Username</th>";
    echo "<th>Email</th>";
    echo "<th>Postal code</th>";
    echo "<th>Phone number</th>";
    echo "<th>Order status</th>";
    echo "</tr>";
    while ($row = mysqli_fetch_array($result1)) {

        echo "<tr>\n";
        echo "<td>".$row["id"]."</td>\n";
        echo "<td>".$row["paintingname"]."</td>\n";
        echo "<td>".$row["username"]."</td>\n";
        echo "<td>".$row["email"]."</td>\n";
        echo "<td>".$row["postalcode"]."</td>\n";
        echo "<td>".$row["phonenumber"]."</td>\n";
        echo "<td>".$row["status"]."</td>\n";
        echo "</tr>\n";
    }
    echo "</table>\n";
}

$conn->close();

?>

</div>
</body>
</html>

您要發布注冊表單來confirm.php ,所以永遠不會執行register.php的代碼

暫無
暫無

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

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