简体   繁体   中英

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. Then a page called "details.php" appears asking for the user to input some more details. Finally a page called "vieworders.php" displays, showing details of the orderand the status of the painting.

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

Question 2: How the user will be able to come back any time and check the status of the painting??

Here is my code:

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的代码

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM