PHP Returns same to record and store different temporary value for variable

Sampe database:
id | username | payer_id | confirmation | other_info
1 | trillzglobal | 27 | 2 | …
2 | trillzglobal | 28 | 2 | .>>>>>>>
7 | trillzglobal | 45 | 2 | >>>>>>>

now i try to write a php that select and store the id and payer_id where ever there is user “trillzglobal”
then when confirmation is 2 it should create an html button with hidden detail $id and $payer_id

For the above database, three buttons are created
Challenge: every time i click any of the buttons it has the last id=7 and payers_id = 45 stored in all of them

MY CODE IS attached and this is it

[php]
if (mysqli_num_rows($num) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($num)) {

$id =  $row['id'];
$username_text =  $row['username_text'];  
$id_payer =  $row['id_payer'] ;

if($Confirmation_No == 2){
	echo"<form action='button.php' method='post'>
				<input type='submit' value='CONFIRM' name='submit'>
				<input type='hidden' name='id' value='$id'>
				<input type='hidden' name='id' value='$id_payer'>
				</form>";
		}

[/php]


Don’t use variables in queries. Even coming from a session it could be tampered with.

Why are you doing a fetch in a loop? Conceivably, MembersInfo should only hold a single record for a single username. If that isn’t the case, you need to reevaluate your data model.

the $Confirmation_no isn’t even needed. You should include that in the where clause to ONLY get the records back matching that requirement.

Thanks for the reply. The members info is like a page containing wages of worker and montly weekly record… so when user go on their page they can find them sequentially… that is the reason for the fetch within loop.
Also i need user to be able to perform action on each one. So i had to store each id with the form generated but its saving only the last id for all button

You named both hidden fields the same thing. When the form posts, it will give the last element with that name.

any Idea on how to go about it and get all needed information for each row where a particular username comes up.

My way would be to use a button with the id of that particular row. Or use a front enf framework like angular where it is linked.

[php]Confirm[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service