Does anyone now how to take a user's info from a database and display it in checkboxes, with the checkboxes corresponding to certain variables either checked or not, depending on the user's data? I'm rather new to PHP and mysql. Any help is much appreciated.
Well to return data from a database you use a SELECT query and then you get this returned data and echo it out in a form as normal, and you can use an if statement to decide whether to check a box or not. You should get used to running querys to query your database and echoing out data from a database as they take a simple format and they are easy to get used to.
If you are looking for some sample code, let me give you an example of what wd_2k6 tried to explain (if he does not mind ) I will suppose that your database has yes for checked and no for not checked (could be anything else such as 1 or 0) So you would do something like this <?php //database connection $query = “select values from your_table where your_condition"; $result = mysql_query($query); echo '<form action="" method="post">'; while($row = mysql_fetch_array($result)){ if($row['value1'] == "yes") echo '<input name="value1" type="checkbox" value="" checked />Value1'; else echo '<input name="value1" type="checkbox" value="" />Value1'; // do the same thing for the other values . . . . }//end while echo '</form>'; ?> PHP: hope this helps
Course I don't mind @Edgar_fox this is the basic standard way to take information out of a database, you retrieve it and loop through it, there's nothing else to it. Once you understand this concept it's easy.