gpt4 book ai didi

php - 登记表.php

转载 作者:行者123 更新时间:2023-11-29 16:47:18 25 4
gpt4 key购买 nike

我正在开发一个网页,在其中显示有关绘画的信息。

我创建了一个名为“register.php”的网页,用户在订购绘画之前必须填写注册表。然后出现一个名为“details.php”的页面,要求用户输入更多详细信息。最后会显示一个名为“vieworders.php”的页面,显示订单的详细信息和绘画的状态。

问题1:我创建了一个名为“users”的数据库,其中包含以下字段“id(主键自增),用户名,电子邮件和密码。为什么当用户提交注册表单时,数据没有显示在我的数据库??

问题2:用户如何能够随时返回并检查绘画的状态?

这是我的代码:

注册.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>

详细信息.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 中的代码永远不会执行

关于php - 登记表.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53032100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com