0

Hi!
I am new in PHP.
I have a table which stores user surnames and 12 months each having a value of 1 or 0.
I need via a form in PHP to check whether or not this value is 1 or 0,
and be able to control this values via checkboxes (when the value is 1 the checkbox is checked and viseversa: when the checkbox is checked, then update the database.
The code I wrote is this:

while($row = mysql_fetch_array($result))
                      {
                        echo "<tr>";
                        echo "<td>" . $row['Surname'] . "</td>";
                        $rownum=mysql_num_rows($result);
                        if  ($row['Jan']==1)
                        {
                        echo "<td><input type='checkbox' name='month[$row]' checked='True'/>" . "</td>";
                        }
                        else
                        {
                        echo "<td><input type='checkbox' name='month[$row]' checked='False'/>" . "</td>";
                        }

It displays the 2 users I already have, but if the value in the database is 1 then for both users the checkbox gets checked...
Any help appreciated

Edited by Reverend Jim: Fixed formatting

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by anasp
0

I think it is your html that is the problem. The 'checked' parameter can take 'yes' or 'no' as parameters. Normally, I would just use the word 'checked' on the one to be turned on as it defaults to 'yes'.

0

Thank you very much chris!!!
It worked but now I'm trying to solve the rest of the problem
(updating the specific user's record in the database someone checks or unchecks a specific checkbutton)...
thank you once more...!

0

Maybe I have not been very specific in describing my problem.
I have a database with a 2 tables. one that stores users and another that stores payment (if a user has paid his/hers subscription per month) when a user has payed for January lets say, January field has the value of 1 for this user, otherwise the value 0.
In my website I have one form via which the administrator can check which user has payed for which months (there is a table with columns the user and the 12 months of a year and rows user surnames. under every month there is a checkbox that shows of the user has payed for this month or not. Thus, I need to specify which checkbox has changed for which user and to update the database.
I hope this time my description helps more
Thank you in advance!!!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.