Jump to content


Photo

Checking a form


  • Please log in to reply
2 replies to this topic

#1 mATOK

mATOK
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts
  • LocationToronto, Ontario

Posted 04 October 2006 - 02:13 PM

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
"Not everything that counts can be counted, and not everything that can be counted counts."

W3 Web Tutorials | Check Your html | CSS layout techniques | ALA | Zen Garden | CSS Links

Navs with flavor | CSS Playground | CSS boxes

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 04 October 2006 - 02:25 PM

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:
<?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());
?>

Please post the source for your form.

Ken

#3 mATOK

mATOK
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts
  • LocationToronto, Ontario

Posted 04 October 2006 - 02:55 PM

<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>&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>
                        </table>,</form>

in my table what I will end up with 1 row for each market checked
"Not everything that counts can be counted, and not everything that can be counted counts."

W3 Web Tutorials | Check Your html | CSS layout techniques | ALA | Zen Garden | CSS Links

Navs with flavor | CSS Playground | CSS boxes




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users