Jump to content

Checking a form


mATOK

Recommended Posts

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
Link to comment
Share on other sites

[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>&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>
[/code]

in my table what I will end up with 1 row for each market checked
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.