Help with checkbox

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
suhailasif
Forum Newbie
Posts: 3
Joined: Thu Aug 06, 2009 11:55 am

Help with checkbox

Post by suhailasif »

Hi,

I am a web developer and i am going through the phase of learning php. I have a problem these days for which i am seeking a solution. If anyone of you can help i would be grateful. I am making an application in which i want to place a checkbox in the admin panel of the site. The work of the checkbox is that it shows a page on the front end. If the checkbox is checked the page shows up at the front end and if unchecked it does not.

The problem is that when i check the box it updated the database and the page starts showing up but the problem is that whenever the setting page is loaded again the checkbox becomes unchecked and their is no way to update the database.

Please help me to make a checkbox which should a show checked or unchecked depending upon the database value. I store 1 for checked in the database. I would be grateful if any of you guys can put the solution.

Regards
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Help with checkbox

Post by aceconcepts »

What you will need to do is check the database and depending on the status, set the "checked" attribute for the checkbox.

e.g.

Code: Select all

 
$checked="";
$query = mysql_query("SELECT checkStatus FROM tbl");
$row = mysql_fetch_array($query);
if($row['checkStatus']==1){ $checked='checked="checked"'; }
echo'<input type="checkbox" $checked />';
 
I hope this works for you.
suhailasif
Forum Newbie
Posts: 3
Joined: Thu Aug 06, 2009 11:55 am

Re: Help with checkbox

Post by suhailasif »

Hi,

Thanks for the reply. It really helped.

Regards
Post Reply