Hi there,
I would like to make it for the user possible to update several rows in a database at once.
e.g.
Fruit | user
apple | mark
orange | sam
In an input mask; the user makes all the changes to both rows and post it to the same page.
The same page capture the post variables.
For that purpose I made this line within a loop with hidden input fields.
<input type=\"hidden\" name=\"Fruitupdate" . $counter . "\" value=\"" . $row["Fruit"] . "\">"
<input type=\"hidden\" name=\"Fruit_before" . $counter . "\" value=\"" . $row["Fruit"] . "\">"
<input type=\"hidden\" name=\"userupdate" . $counter . "\" value=\"" . $row["user"] . "\">"
<input type=\"hidden\" name=\"user_before" . $counter . "\" value=\"" . $row["user"] . "\">"
Outside the loop we have the counter
echo "<input type=\"hidden\" name=\"counter\" value=\"" . $counter . "\">"
In our case with an apple and an prange, there would be 9 Post variables called Fruitupdate1, Fruitupdate2, Fruit_before1, Fruit_before2, userupdate1, userupdate2, user_before1 and user_before2 and $counter right?
Ok, so far its easy, but now comes the second part after submitting to the same page and the proper session and if statement, we come to a different part of code instead of the old selection part.
Here it shall just update the values in the database with the new values.
for($i=1;$i<=$_POST['counter'];$i++) {
$query = "UPDATE garden SET Fruit = \"" . $_POST['Fruit_update" . $i . "'] . "\", user = \"" . $_POST['userupdate" . $i . "'] . "\" WHERE ((Fruit = \"" . $_POST['Fruit_before" . $i . "'] . "\") AND (user = \"" . $_POST['user_before" . $i . "'] . "\"))";
The query String doesn't get created properly. The reason is that the parser translate the $i (the counter) first and doesn't understand to use the new name as an actual reference to a POST variable.
In other words having variable within variable seems not to be possible. I don't know how to do that.
Antycomments?
Thanks
Ros