[英]Passing variable via submit button
Im loading content for my website from database. 我正在从数据库中为我的网站加载内容。 It loads data and fills a table.
它加载数据并填写表格。 My problem is that i have put a button next to each row.
我的问题是我在每行旁边都放了一个按钮。 When i click on the button it has to show me the Name, Price ,Stock etc of every row.
当我单击按钮时,必须向我显示每一行的名称,价格,库存等。
When i click on the button i get an error. 当我单击按钮时,出现错误。
Here you can find the code i have written in de document User_Koeken.php 在这里您可以找到我在文档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> ";
}; }?>
Here you can find a picture of my code in color http://postimg.org/image/n6wrb0d13/ 在这里您可以找到我的代码的图片,颜色为http://postimg.org/image/n6wrb0d13/
http://postimg.org/image/n6wrb0d13/ http://postimg.org/image/n6wrb0d13/
$ID
must be initialized before the line $ID
必须在行之前初始化
if (isset($_POST[$ID]))
Otherwise, this will always return false, or an error. 否则,它将始终返回false或错误。
Instead, use an array in your HTML names to catch the row being posted: 而是使用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>
and the PHP: 和PHP:
if (isset($_POST['myform']) ) {
$post = $_POST['myform'];
$ID = $post['id'];
$URL = $post['S_URL'];
....
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.