gpt4 book ai didi

PHP 将一个用户的数据转移到另一个页面

转载 作者:太空宇宙 更新时间:2023-11-03 11:11:31 25 4
gpt4 key购买 nike

我在电子商务网站上有一个管理区域,管理员可以在其中查看 allusers.php 页面上的所有用户。用户在表格中列出了他们的个人信息,但是我在每个用户附近都有一个“查看个人资料”按钮,如果您单击它,它将带您到另一个页面,您可以在其中查看特定用户过去的订单。

以下是我为 allusers.php 编写的代码:

    <?php

$result = mysql_query("SELECT * FROM customers ")
or die(mysql_error()); ;

if (mysql_num_rows($result) == 0) {
echo 'There Arent Any Orders Yet';
} else {

echo "<table border='0'><table border width=100%><tr><th>First Name</th><th>Surname</th><th>Address</th><th>E-Mail</th><th>Username</th><th>View Profile</th>";
while($info = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $info['name']. "</td>";
echo "<td>" . $info['surname']. "</td>";
echo "<td>" . $info['address1']. $info['address2']. $info['city']. $info['postcode']." </td>";
echo "<td>" . $info['email']. "</td>";
echo "<td>" . $info['username']. "</td>";
echo "<td>" . " <a href='view.php'>View</a> </td>";


}
}
echo "</tr>";
echo "</table>";
?>

view.php页面如下:

<?php


$result = mysql_query("SELECT * FROM order WHERE ......dont know what to enter here")
or die(mysql_error()); ;

if (mysql_num_rows($result) == 0) {
echo 'There Arent Any Orders For This Customer Yet';
} else {

echo "<table border='0'><table border width=100%><tr><th>Product</th><th>Quantities</th><th>Date</th>";
while($info = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $info['name']. "</td>";
echo "<td>" . $info['quantity']. "</td>";
echo "<td>" . $info['date']. " </td>";
}
}
echo "</tr>";
echo "</table>";
?>

我有一个包含以下字段和表的 mysql 数据库:

客户 - id, name, surname, address1, address2, city, postcode, email, username, password

产品 - 序列号、名称、描述、价格、图片

订单 - id、名称、数量、价格、日期、用户名

感谢您提供的任何帮助

最佳答案

您的代码缺乏任何类型的安全机制...这非常糟糕,尤其是在电子商务环境中。

请原谅,您会将用户名传递给 URL 中的查看页面。

echo "<td>" . " <a href='view.php?user=" . $info['username'] . "'>View</a> </td>";

在您的 View 页面中,您将从 URL 中获取参数并将其包含在您的查询中。

if (isset($_GET) && isset($_GET['user'])) {
$user = mysql_real_escape_string($_GET['user']);
} else {
header('Location: allusers.php');
exit(); // boot them back to the previous page.
}
$result = mysql_query("SELECT * FROM order WHERE username = '" . $user . "'")

关于PHP 将一个用户的数据转移到另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8235298/

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