The PHP _POST problem doesn't make sense. values ​​disappear?

So this does not bother me. I have a page (index.php) that has lines. The lines look like this:

enter image description here

enter image description here

enter image description here

enter image description here

And so on ... as you can see from the code below, I added debug statements to show passID (800 numbers) and rowID (serial)

echo "{$row['ID']}"; echo" <form action=\"./functions/email.php\" id='passForm' method='post'> <input type='hidden' id='passID' name='passID' value='{$row['ID']}'/> <input type='hidden' id='rowID' name='rowID' value='$rowID'/> <button type=\"submit\" form=\"passForm\" value=\"Submit\" style=\"height:25px; width:75px\">Pass</button> </form>"; echo "$rowID"; 

When I click on a specific line (say 860, as shown here in the developer console) enter image description here

When we view our results on the email.php page using the code

 $projectID = $_POST['passID']; $rowID = $_POST['rowID']; echo $projectID; echo "<br />"; echo $rowID; 

We see that the value has changed to 865 and line 1 instead of the expected 860 and line 3 ?!

enter image description here

That doesn't make sense to me. How can this happen? The html page displays the correct line values, as shown in the debug screenshot, and how this is done when the code simply picks up the top line on the next page. What's happening?!

As you can see, any help would be much appreciated lol, because I may or may not go crazy looking at it!

+5
source share
1 answer

The problem is the form="passForm" attribute in the submit button. This forces all submit buttons to submit the form on the first line. If you do not take this attribute into account, the submit button is applied to its contained form in the current line, which is what you need.

You must either remove the id attributes from all of your elements or make them unique by including the row identifier in the identifiers, since the identifiers must be unique.

+9
source

All Articles