So this is beyond confusing for me. I have a page (index.php) that has rows. The rows print out looking like this
And so on...as you can see from the code below I have added debugging statements to show the passID (800 numbers) and the rowID(sequential)
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 particular row (let's say 860 as shown in the developer console 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 row 1 instead of the expected 860 and row 3?!
This makes NO sense to me. How can this be happening? The html page renders with the row values correct as shown in the debug screenshot so how is it that the code is just picking up the top row on the next page. What is going on??!
As you can see, any help would be greatly appreciated lol because I may or may not go crazy staring at this!
The problem is the form="passForm"
attribute in the submit button. It's causing all the submit buttons to submit the form in the first row. If you leave out this attribute, the submit button applies to its containing form in the current row, which is what you want.
You should also either remove the id
attributes from all your elements, or make them unique by including the row ID in the IDs, because IDs need to be unique.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With