PHP _POST issue making no sense. values disappearing?
Asked Answered
A

1

5

So this is beyond confusing for me. I have a page (index.php) that has rows. The rows print out looking 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 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) 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 row 1 instead of the expected 860 and row 3?!

enter image description here

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!

Apeman answered 8/9, 2015 at 14:47 Comment(1)
So you've got multiple forms / buttons / fields with duplicated ids? i.e. passForm These should be unique to each form.Owensby
A
9

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.

Alcmene answered 8/9, 2015 at 14:53 Comment(2)
Simple, yet effective.Stahl
Whelp. A little missunderstanding goes a long way. Thank you for correcting me. Jeez, can't believe I didn't realize that. Thank you!Apeman

© 2022 - 2024 — McMap. All rights reserved.