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

Recommended Answers

All 3 Replies

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'.

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...!

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!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.