Jump to content


This topic is now archived and is closed to further replies.


Checking a form

Recommended Posts

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

Share this post

Link to post
Share on other sites
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:
$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());

Please post the source for your form.


Share this post

Link to post
Share on other sites
<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><td><input type="checkbox" name="TC">Total Canada</td><td>&nbsp;</td><td><input type="checkbox" name="OB">OB</td></tr>
                                <tr><td><input type="checkbox" name="TD">T
</td><td>&nbsp;</td><td><input type="checkbox" name="M">MS</td></tr>
                                <tr><td><input type="checkbox" name="MF">MF</td><td>&nbsp;</td><td><input type="checkbox" name="O">O</td></tr>
                                <tr><td><input type="checkbox" name="VD">VDDMA</td><td>&nbsp;</td><td><input type="checkbox" name="TC">TC</td></tr>
                                <tr><td><input type="checkbox" name="BB">BB</td><td>&nbsp;</td><td><input type="checkbox" name="HC">HC</td></tr>
                                <tr><td><input type="checkbox" name="CD">CD</td><td>&nbsp;</td><td><input type="checkbox" name="A">A</td></tr>
                                <tr><td><input type="checkbox" name="AB">AB</td><td>&nbsp;</td><td><input type="checkbox" name="B">B</td></tr>
                                <tr><td><input type="checkbox" name="QB">QB</td><td>&nbsp;</td><td><input type="checkbox" name="VC">VC</td></tr>
                                <tr><td><input type="checkbox" name="Q">Q</td><td>&nbsp;</td><td><input type="checkbox" name="Vic">Vic</td></tr>
                                <tr><td><input type="checkbox" name="A">A</td><td>&nbsp;</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>

in my table what I will end up with 1 row for each market checked

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.