Can Only Post First Result Of While Loop
I am using a while loop to display results from a query. The while loop is working fine. In hidden fields I would like to post the values of userID and accessID to the user details
Solution 1:
you are generating multiple <form>
s inside loop, move your <form>
outside while
loop, like:
<formmethod="post"action="edit_user.php"id="userForm"><?phpwhile($row = $result->fetch_array()) { ?><tr><td><ahref="#"><?phpecho$row['firstname'].' '.$row['surname']; ?></a><inputtype="hidden"name="userID[]"value="<?phpecho$row['userID']; ?>" /><inputtype="hidden"name="accessID[]"value="<?phpecho$row['accessID']; ?>" /></td></tr><?php } ?><ahref="#"onclick="return submitForm();">Submit</a></form>
Solution 2:
You're running into trouble because of this line
var form = document.getElementById("userForm");
In Javascript and HTML, an ID is supposed to be unique to a certain DOM element. In this case, you've got a whole load of form tags that have the same ID. You need to give each form a different ID, and then pass that ID to the submitForm function.
For example:
<?php$id = 0;
while($row = $result->fetch_array()) { ?>
$id++;
<formmethod="post"action="edit_user.php"id="<?phpecho"userForm".$id?>"><tr><td><ahref="#"onclick="return(submitForm("<?phpecho"userForm".$id?>"))"><?phpecho$row['firstname'].' '.$row['surname']; ?></a><inputtype="hidden"name="userID"value="<?phpecho$row['userID']; ?>" /><inputtype="hidden"name="accessID"value="<?phpecho$row['accessID']; ?>" /></td></tr></form><?php } ?>
and then
functionsubmitForm(id) {
var form = document.getElementById(id);
form.submit();
}
edit: how do I php? :D
Post a Comment for "Can Only Post First Result Of While Loop"