Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP _POST issue making no sense. values disappearing?

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!

like image 928
new2programming Avatar asked Sep 08 '15 14:09

new2programming


1 Answers

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.

like image 133
Barmar Avatar answered Nov 23 '22 15:11

Barmar