我从数据库加载我网站的内容。它加载数据并填充表格。 我的问题是我在每一行旁边放了一个按钮。当我点击按钮时,它必须显示每行的名称,价格,库存等。
当我点击按钮时出现错误。
在这里,您可以找到我在de文档User_Koeken.php中编写的代码
<?php
if (isset($_POST[$ID]))
{
$URL = $_POST['S_URL'];
$Naam = $_POST['S_Naam'];
$Inhoud = $_POST['S_Inhoud'];
$Stock = $_POST['S_Stock'];
$Prijs = $_POST['S_Prijs'];
echo $URL."".$Naam."".$Inhoud."".$Stock."".$Prijs;
}
else
{$supermarket = mysql_connect("localhost", "root", "Password") or die(mysql_error());
mysql_select_db("supermarket", $supermarket);
$sql = " select * from koeken";
$result = mysql_query($sql, $supermarket);
while ($row = mysql_fetch_array($result)) {
$ID = $row['ID'];
$URL = $row['URL'];
$Naam = $row['Naam'];
$Inhoud = $row['Inhoud'];
$Stock = $row['Stock'];
$Prijs = $row['Prijs'];
$_SESSION['ID']=$ID;
echo "<form action='User_Koeken.php' method='post'>
<tr class='rien' >
<td name='S_URL'><a href=$URL><img src=$URL alt='product'></a></td>
<td name='S_Naam'>$Naam</td>
<td Name='S_Inhoud'>$Inhoud</td>
<td name='S_Stock'>$Stock</td>
<td name='S_Prijs'>€ $Prijs</td>
<td><input type='submit' value=$ID name='$ID'></td>
</tr>
</form> ";
}; }?>
在这里,您可以找到我的代码颜色的图片 http://postimg.org/image/n6wrb0d13/
答案 0 :(得分:0)
$ID
必须在行之前初始化
if (isset($_POST[$ID]))
否则,这将始终返回false或错误。
相反,在HTML名称中使用数组来捕获要发布的行:
<tr class='rien' >
<td name='myform[S_URL]'><a href='$URL'><img src='$URL' alt='product'></a></td>
<td name='myform[S_Naam]'>$Naam</td>
<td Name='myform[S_Inhoud]'>$Inhoud</td>
<td name='myform[S_Stock]'>$Stock</td>
<td name='myform[S_Prijs]'>€ $Prijs</td>
<td><input type='submit' value='$ID' name='myform[id]'></td>
</tr>
和PHP:
if (isset($_POST['myform']) ) {
$post = $_POST['myform'];
$ID = $post['id'];
$URL = $post['S_URL'];
....
}