mATOK Posted October 4, 2006 Share Posted October 4, 2006 I have a form with 20 check boxes. Depending upon what is checked I will build an sql statment.I have no idea what the best way to do this is and would love to hear some suggestions.Thank you Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted October 4, 2006 Share Posted October 4, 2006 This can be very simple, if the field names in your form are the same as the field names in your database, you can do something like:[code]<?php$qtmp = array();foreach($_POST as $fld => $val) if ($fld != 'submit') // skip the submit button $qtmp = $fld . " ='" . mysql_real_escape_string(stripslashes($val)) . "'";$q = 'insert into tablename set ' . implode(', ',$qtmp);$rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());?>[/code]Please post the source for your form.Ken Quote Link to comment Share on other sites More sharing options...
mATOK Posted October 4, 2006 Author Share Posted October 4, 2006 [code]<form name=\"Add-Client\" action=\"connect.php\" method=\"get\">";?> <table border="0"> <tr><td>Client Name</td><td><input type="text" name="cname" size="30" /></td></tr> <tr><td>Number of Users</td><td><input type="text" name="numusrs" size="3" /></td></tr> </table><table border="0"> <tr><th>Markets</th></tr> <tr><td><input type="checkbox" name="TC">Total Canada</td><td> </td><td><input type="checkbox" name="OB">OB</td></tr> <tr><td><input type="checkbox" name="TD">T</td><td> </td><td><input type="checkbox" name="M">MS</td></tr> <tr><td><input type="checkbox" name="MF">MF</td><td> </td><td><input type="checkbox" name="O">O</td></tr> <tr><td><input type="checkbox" name="VD">VDDMA</td><td> </td><td><input type="checkbox" name="TC">TC</td></tr> <tr><td><input type="checkbox" name="BB">BB</td><td> </td><td><input type="checkbox" name="HC">HC</td></tr> <tr><td><input type="checkbox" name="CD">CD</td><td> </td><td><input type="checkbox" name="A">A</td></tr> <tr><td><input type="checkbox" name="AB">AB</td><td> </td><td><input type="checkbox" name="B">B</td></tr> <tr><td><input type="checkbox" name="QB">QB</td><td> </td><td><input type="checkbox" name="VC">VC</td></tr> <tr><td><input type="checkbox" name="Q">Q</td><td> </td><td><input type="checkbox" name="Vic">Vic</td></tr> <tr><td><input type="checkbox" name="A">A</td><td> </td><td><input type="checkbox" name="CC">CC</td></tr> <tr><td colspan="2"><input type="checkbox" name="CH">CH</td> <input type="hidden" name="task" value="7" /> <tr><td colspan="2"><br /><input type="Submit" value="Submit"></td></tr> </table>,</form>[/code]in my table what I will end up with 1 row for each market checked 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.