在php中单击链接(来自数据库)后,没有显示任何内容
我有一个名为在php中单击链接(来自数据库)后,没有显示任何内容,php,html,mysql,sql,database,Php,Html,Mysql,Sql,Database,我有一个名为simple\u stall的数据库,其中包含表order\u detail,该表有4列IDNameOrdered\u Item数量…当前用户提交订单后,他们将被重定向到一个名为order\u detail.php…的页面。此页面将显示表中所有订购的项目,标题为ID名称订购的项目数量 现在,当用户从表中单击某人的姓名时,我想将用户重定向到一个名为view\u more.php的新页面,该页面将显示用户订购的项目,但是页面中没有显示任何内容 这是我的代码: index.php <
simple\u stall
的数据库,其中包含表order\u detail
,该表有4列ID
NameOrdered\u Item数量
…当前用户提交订单后,他们将被重定向到一个名为order\u detail.php
…的页面。此页面将显示表中所有订购的项目,标题为ID
名称订购的项目
数量
现在,当用户从表中单击某人的姓名时,我想将用户重定向到一个名为view\u more.php
的新页面,该页面将显示用户订购的项目,但是页面中没有显示任何内容
这是我的代码:
index.php
<div class="container">
<form action="insert_data.php" method="POST">
<div>
<input type="text" name="Name" placeholder="Name">
</div>
<div>
<input type="text" name="Order" placeholder="Order">
</div>
<div>
<input type="text" name="Quantity" placeholder="Quantity">
</div>
<div>
<button type="submit" name="submit">Send Order</button>
</div>
</form>
</div>
if (isset($_POST['submit']))
{
include_once 'dbh.php';
// Escape user inputs for security
$name = mysqli_real_escape_string($connection, $_POST['Name']);
$order = mysqli_real_escape_string($connection, $_POST['Order']);
$quantity = mysqli_real_escape_string($connection, $_POST['Quantity']);
// attempt insert query execution
$sql = "INSERT INTO order_detail (Name, Ordered_Item, Quantity) VALUES ('$name', '$order', '$quantity')";
if(mysqli_query($connection, $sql))
header("Location: ./order_detail.php?status=ordered");
else
echo "ERROR: Could not able to execute $sql. " . mysqli_error($connection);
// close connection
mysqli_close($connection);
}
else
{
header("Location: ./index.php?status=failed");
exit();
}
<body>
<table>
<tr>
<th width="30px">No</th>
<th width="30%">Name</th>
<th width="30%">Ordered Item</th>
<th width="50px">Quantity</th>
</tr>
<?php
include_once 'dbh.php';
$query = "SELECT * FROM order_detail"; //You don't need a ; like you do in SQL
$result = mysqli_query($connection, $query);
echo "<table border = 1px>"; // start a table tag in the HTML
while($row = mysqli_fetch_array($result))
{
$name = $row['Name'];
//Creates a loop to loop through results
echo "<tr><td style = 'width:30px;'>" . $row['ID'] . "</td>
<td style = 'width:30%;'>" . "<a href='view_more.php?id=$name'>" . $row['Name'] . "</td>
<td style = 'width:30%;'>" . $row['Ordered_Item'] . "</td>
<td>" . $row['Quantity'] . "</td></tr>"; //$row['index'] the index here is a field name
}
echo "</table>"; //Close the table in HTML
mysqli_close($connection); //Make sure to close out the database connection
?>
if (isset($_POST['Name']))
{
include_once 'dbh.php';
$name = $row['Name'];
$query = "SELECT * FROM order_detail WHERE Name = $name";
$result = mysqli_query($connection, $query);
echo "<table border = 1px>"; // start a table tag in the HTML
while($row = mysqli_fetch_array($result))
{
//Creates a loop to loop through results
echo "<tr><td style = 'width:30px;'>" . $row['ID'] . "</td>
<td style = 'width:30%;'>" . $row['Name'] . "</td>
<td style = 'width:30%;'>" . $row['Ordered_Item'] . "</td>
<td>" . $row['Quantity'] . "</td></tr>"; //$row['index'] the index here is a field name
}
echo "</table>"; //Close the table in HTML
mysqli_close($connection);
}
order\u detail.php
<div class="container">
<form action="insert_data.php" method="POST">
<div>
<input type="text" name="Name" placeholder="Name">
</div>
<div>
<input type="text" name="Order" placeholder="Order">
</div>
<div>
<input type="text" name="Quantity" placeholder="Quantity">
</div>
<div>
<button type="submit" name="submit">Send Order</button>
</div>
</form>
</div>
if (isset($_POST['submit']))
{
include_once 'dbh.php';
// Escape user inputs for security
$name = mysqli_real_escape_string($connection, $_POST['Name']);
$order = mysqli_real_escape_string($connection, $_POST['Order']);
$quantity = mysqli_real_escape_string($connection, $_POST['Quantity']);
// attempt insert query execution
$sql = "INSERT INTO order_detail (Name, Ordered_Item, Quantity) VALUES ('$name', '$order', '$quantity')";
if(mysqli_query($connection, $sql))
header("Location: ./order_detail.php?status=ordered");
else
echo "ERROR: Could not able to execute $sql. " . mysqli_error($connection);
// close connection
mysqli_close($connection);
}
else
{
header("Location: ./index.php?status=failed");
exit();
}
<body>
<table>
<tr>
<th width="30px">No</th>
<th width="30%">Name</th>
<th width="30%">Ordered Item</th>
<th width="50px">Quantity</th>
</tr>
<?php
include_once 'dbh.php';
$query = "SELECT * FROM order_detail"; //You don't need a ; like you do in SQL
$result = mysqli_query($connection, $query);
echo "<table border = 1px>"; // start a table tag in the HTML
while($row = mysqli_fetch_array($result))
{
$name = $row['Name'];
//Creates a loop to loop through results
echo "<tr><td style = 'width:30px;'>" . $row['ID'] . "</td>
<td style = 'width:30%;'>" . "<a href='view_more.php?id=$name'>" . $row['Name'] . "</td>
<td style = 'width:30%;'>" . $row['Ordered_Item'] . "</td>
<td>" . $row['Quantity'] . "</td></tr>"; //$row['index'] the index here is a field name
}
echo "</table>"; //Close the table in HTML
mysqli_close($connection); //Make sure to close out the database connection
?>
if (isset($_POST['Name']))
{
include_once 'dbh.php';
$name = $row['Name'];
$query = "SELECT * FROM order_detail WHERE Name = $name";
$result = mysqli_query($connection, $query);
echo "<table border = 1px>"; // start a table tag in the HTML
while($row = mysqli_fetch_array($result))
{
//Creates a loop to loop through results
echo "<tr><td style = 'width:30px;'>" . $row['ID'] . "</td>
<td style = 'width:30%;'>" . $row['Name'] . "</td>
<td style = 'width:30%;'>" . $row['Ordered_Item'] . "</td>
<td>" . $row['Quantity'] . "</td></tr>"; //$row['index'] the index here is a field name
}
echo "</table>"; //Close the table in HTML
mysqli_close($connection);
}
它不会显示
因为在view\u more.php
上你有if(isset($\u POST['Name'])
,这永远不会是真的,因为你在view\u more.php
上没有使用$\u POST
,你使用的是。“$row['Name']”。
你使用的是普通链接,所以用这个代码替换它
if (isset($_GET['id']))
{
include_once 'dbh.php';
$name = $_GET['id'];
$query = "SELECT * FROM order_detail WHERE Name = '$name'";
$result = mysqli_query($connection, $query);
echo "<table border = 1px>"; // start a table tag in the HTML
while($row = mysqli_fetch_array($result))
{
//Creates a loop to loop through results
echo "<tr><td style = 'width:30px;'>" . $row['ID'] . "</td>
<td style = 'width:30%;'>" . $row['Name'] . "</td>
<td style = 'width:30%;'>" . $row['Ordered_Item'] . "</td>
<td>" . $row['Quantity'] . "</td></tr>"; //$row['index'] the index here is a field name
}
echo "</table>"; //Close the table in HTML
mysqli_close($connection);
}
if(isset($\u GET['id']))
{
包括_one'dbh.php';
$name=$_GET['id'];
$query=“从订单详细信息中选择*,其中名称='$Name';
$result=mysqli\u查询($connection,$query);
echo”“;//在HTML中启动一个表标记
while($row=mysqli\u fetch\u数组($result))
{
//创建循环以循环结果
回显“.$row['ID']”
“$row['Name']”
“$row[‘订购的商品’]”。”
“$row['Quantity']”;//$row['index']此处的索引是字段名
}
echo”“;//在HTML中关闭表
mysqli_close($connection);
}
您应该很乐意去做,但是,我强烈建议您使用适当的php框架。在生成指向查看\u more.php
页面的链接时,您正在注入一个名为id
的GET参数:
<a href='view_more.php?id=$name'>
把这个固定到
if (isset($_GET['id']))
顺便说一句,你的代码真的很难看。有很多事情做错了:
- SQL查询中未替换的参数:您将面临严重的安全漏洞
- 耦合的PHP和HTML脚本:查看和
嘿,谢谢..但现在显示了警告:mysqli\u fetch\u array()希望参数1是mysqli\u结果,在第14行的C:\xampp\htdocs\simple\u stall\view\u more.php中给出布尔值
有什么原因吗?另外,你所说的php框架是什么意思?像method=post
?返回空白页哦,等等,在order\u detail.php
中发现错误的代码它可以工作!谢谢~