简体   繁体   English

注册表php

[英]registration form php

I am working on a web page in which i display information about paintings. 我正在一个网页上显示有关绘画的信息。

I created a web page called "register.php" in which the user before placing an order of a painting has to fill a register form. 我创建了一个名为“ register.php”的网页,在该网页中,用户在下达绘画订单之前必须先填写注册表。 Then a page called "details.php" appears asking for the user to input some more details. 然后出现一个名为“ details.php”的页面,要求用户输入更多详细信息。 Finally a page called "vieworders.php" displays, showing details of the orderand the status of the painting. 最后,显示一个名为“ vieworders.php”的页面,其中显示了订单的详细信息和绘画状态。

Question 1: I have created a database called "users" which have the following fields "id(primary key auto increment),username,email and password. Why when the user submit the registration form, data are not showing up in my database?? 问题1:我创建了一个名为“用户”的数据库,该数据库具有以下字段:“ id(主键自动递增),用户名,电子邮件和密码。为什么当用户提交注册表格时,数据没有显示在我的数据库中? ?

Question 2: How the user will be able to come back any time and check the status of the painting?? 问题2:用户如何能够随时回来查看绘画状态?

Here is my code: 这是我的代码:

register.php 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 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 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