I’m trying to make a page in php that takes rows from a database, displays them, and then give the viewer a chance to upvote or downvote a specific entry. Here is a snippet:
echo('<form action=\'vote.php\' method=\'post\'> \n'); echo('<INPUT type=\'hidden\' name=\'idnum\' value=\''.$row[0].'\'>'); echo('<INPUT type=\'submit\' name=\'up\' value=\'Upvote.\'> \n'); echo('<INPUT type=\'submit\' name=\'down\' value=\'Downvote\'> '); echo('<form/>\n');
The problem is when I hit a submit button, the value for idnum that gets sent is based on the one farthest down it seems. So my questions is, when a submit button is pressed, are the values for all inputs on a page sent?
Your form tag isn’t closed properly. You have
<form/>, but it should be</form>.This makes the entire page a form so it sends all the inputs. With a form that is closed properly though, it will only send the inputs within the form tags that the pressed button was in.