username01 Posted February 23, 2011 Share Posted February 23, 2011 Hi. I want to put data from these checkboxes (example): Jan (value = jan) Chris (value = chris) Tom (value = 50) Jon (unchecked) Put janchris50 to the database after finding correct row with user ID, which is user_id for this example. Then, the user goes to another page and he should see this: Jan (checked) Chris (checked) Tom (checked) Jon (unchecked) In other words - page should get the information from the database and check the checkboxes that appears to be checked in the database. By the way, it should rewrite the row each time, as the user can modify it. Thanks. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted February 23, 2011 Share Posted February 23, 2011 looks like this page might help http://www.homeandlearn.co.uk/php/php4p11.html Quote Link to comment Share on other sites More sharing options...
username01 Posted February 24, 2011 Author Share Posted February 24, 2011 That's for saving the checkboxes if the user goes somewhere out of the site, not to insert them into the database. I'm a newbie and not able to make a SQL code from that code yet, I need something more specific. Thanks. Quote Link to comment Share on other sites More sharing options...
samoht Posted February 24, 2011 Share Posted February 24, 2011 @username01, I don't quite understand your example or what you are asking. Can you be more specific and include what your php code looks like up to this point? Quote Link to comment Share on other sites More sharing options...
username01 Posted February 24, 2011 Author Share Posted February 24, 2011 I need to write data from checked checkboxes into a database table for specific user, which is currently logged in. And after that, when the user enters the same page next time, look up the database and make the checkboxes he checked appear as checked. My current code contains not much for the checkboxes, as I have no idea how to do it: if($session->logged_in){ echo "<div align='center' id='wrap'><form action='process.php' method='post'><fieldset>"; echo "<legend>Choices</legend>"; echo "<p><input class='input' type='checkbox' title='Select anything you want' name='one' id='one' value='a'><label for='one'> Selection #1</label></p>"; // Contains ~10 of these, of course different names. echo "<input type='hidden' name='subprivilegies' value='1'/><br>"; echo "<input type='submit' value='Submit'/>"; echo "</fieldset></form></div>"; It's basically only html code for the checkboxes... Quote Link to comment Share on other sites More sharing options...
samoht Posted February 24, 2011 Share Posted February 24, 2011 Well, you can make your checkboxes all part of an array by naming them the same thing and then adding a bracket set at the end name="mycheckbox[]" but then you will have a separate field in your database for each checkbox. You can name all of the checkboxes the same name="mycheckbox" and then save all the values to the one field in the database - then when you go to retrieve the checkbox data you will need a foreach to loop through each needed checkbox and check if its in the array value for your field to determine if it needs to be "Checked" or not... <?php // set checked field(s) for checkboxes $amounts = array(50,75,100,125,150,200,250,300,500,750,1000); foreach ($amounts as $amount) { echo '<span class="cb"><input type="checkbox" name="checkbox[]" value="'.$amount.'" style="border:0;" '; if (is_array($row['checkbox']) && in_array($amount,$row['checkbox'])) echo 'checked="checked" '; elseif ( !$edit ) echo 'disabled="disabled"'; echo ' /> $'.$amount.'</span>'."\n"; } ?> This example is with generic dollar amounts as the checkbox values - Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.