Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple checkbox - Help 1

Status
Not open for further replies.

w11z

Programmer
Mar 26, 2001
40
0
0
CA
Hello everyone,

I have a form generated by the database (PHP, Postgresql). It displays every client with a checkbox (either checked or unchecked) after the name. The client has to be approved by an admin. The admin approves or uncheck the approve checkbox. After submitting, the database must be updated to reflect the changes made by the admin. Here is the 1st page :
while($row2 = pg_fetch_array($result1))
{
echo "$row2[f_name]". " ";
echo "$row2[l_name]". " ";
echo "<input type='checkbox'";
if ($row2[approved]=='t')
{
echo " value=1 checked ";
}else{
echo " value=0 ";
}
echo "name='app[$row2[client_id]]'></input></td></tr>";
}

How do I loop through the form on the 2nd page to insert into a postgresql DB and to match the client_id with the checked value (either checked or unchecked). The first page is working fine.

Thank in advance
 
Hi

Code:
[b]while[/b] ($row2 = pg_fetch_array($result1)) {                     
  $n=$POST[app][$row2[client_id]]==[i]'1'[/i]?[i]'t'[/i]:[i]'f'[/i];
  [b]if[/b] ($n!=$row2[approved]) {
     $sql=[i]"update the_table set approved=$n where client_id="[/i].$row2[client_id];
     [gray]// execute the SQL statement[/gray]
  }
}
[small]Note : "You should always use quotes around a string literal array index." - PHP docs [/small]

Feherke.
 
Thanks Feherke,

But I don't quite understand. My while loop is on the first page and displays the client that already are in the DB. The 2nd page receives the information from the form of the 1st page. It's in the 2nd page that I update the table. I cannot do a pg_fetch_array on the second page. Can you guide me with that 2nd page?
 
Hi

w11z said:
The 2nd page receives the information from the form of the 1st page.
Yes. But the browser's behavior regarding unchecked checkboxes may differ. For example Mozillas, Opera, Safari and Explorer does not include unchecked checkboxes in the sent information, while others may do.

So you must execute the [tt]select[/tt] statement again then cycle through the list of existing clients like in my code.

Feherke.
 
Feherke,

I understand the idea. Currently when I echo the count($_POST[app][$row2[reu_reg_id]]) it gives me 0. As if nothing was passing from the form to the 2nd page (the update page). This is the HTML output of the 1st page:

<form name='approved' action='test.php' mehod='POST'>
John Doe <input type='checkbox' value='1' checked name='app[127]'></input><br />
Jane Doe <input type='checkbox' value='1' checked name='app[138]'></input><br />
Mike Smith <input type='checkbox' value='0' checked name='app[139]'></input><br />
Brian Wallace <input type='checkbox' value='1' checked name='app[140]'></input><br />
<input type='submit' name='submit' value='Submit'>
</form>

When the 2nd page receive the data from the form (same as above) it seem it doesn't have anything in it.

What am I doing wrong?
 
Thank you very much Feherke. Your code was exactly what I needed. I've found my other problem. You derserve this star...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top