i get data from my mysql database and want to make a list.
in the list i want a button that uses post to send a value to the next page.
$result = mysql_query("SELECT * FROM all");
echo "<table border=\"1\">";
echo"<tr>
<th>ID</th>
<th>Naam</th>
<th>Eigenaar</th>
<th>Plaats</th>
<th>Bewerk</th>
</tr>";
?>
<form action="editshop.php" method="post">
<?php
while($rij = mysql_fetch_array($result))
{
?>
<?php
echo "<tr><td>".$rij['id'] . "</td><td> " . $rij['naam'] ."</td><td>";
echo $rij['eigenaar'] . "</td><td>" . $rij['plaats']."</td>" ;
echo"<input type=\"hidden\" name=\"id\" value=".$rij['id']." /><td><input type=\"submit\" /></td>";
echo "</tr>";
}
echo "</form></table>";
the table looks good but when i pres the button and the editshops.php opens wher i have echo $_POST["id"];
it always the last id of the list.
i only want the number thats the same as the id in the list.
in the list the id’s are shown good.
What have i done wrong
(sorry if the layout of this post is not good this is my firstpost and i dont understand how to highlight the code)
Update
changed the loop to
<?php
while($rij = mysql_fetch_array($result))
{
?>
<form action="bewerkshop.php" method="post">
<?php
echo "<tr><td>".$rij['id'] . "</td><td> " . $rij['naam'] ."</td><td>";
echo $rij['eigenaar'] . "</td><td>" . $rij['plaats']."</td>" ;
echo"<td><input type=\"submit\" name=\"id\" value=\"".$rij['id']."\" /></td>";
echo "</tr>";
}
echo "</form></table>";
?>
all working now but the names of the buttons are the id number can i change it to edit.
so all the buttons say edit and not the id number
NOTE: I’m not sure if you want to edit multiple rows with a submit or only one. My answer is only helpful for editing multiple rows.
You’re writing an input field for each row, all with the same name. That’s the reason why the last one overwrites all the others.
You need to name your input field accordingly.
Example:
Where 1 here is the ID of your row.
You can then iterate over $_POST[‘naam’] and fetch the values.