如何阻止PHP将假行/字段添加到mysql?

时间:2012-07-19 07:06:36

标签: php mysql

这里有8列.. 场景是...... 如果用户之前只有一份就业记录怎么办?如何忽略提交时留空的其他字段?

就业记录

    <table class="main" width="73%" border="0" align="center" cellpadding="0" cellspacing="2">
        <form action='scripts/forms_script3.php' name='forml' method='post'>
            <tr>
                <th>
                    Position Held
                </th>
                <th>
                    Company/Tel. No.
                </th>
                <th>
                    Immediate Head
                </th>
                    <th colspan="2">Inclusive Years<br/>&nbsp;&nbsp;From&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;To&nbsp;&nbsp;&nbsp;&nbsp;</th>
                <th>
                    Hiring Salary
                </th>
                <th>
                    Last Salary
                </th>
                <th>
                    Reason/s for Leaving
                </th>
            </tr>
            <tr>
                <td>
                    <input type='text' name='aposheld' size='20' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='acomtel' size='40' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='aimmhead' size='20' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='afrom' size='5' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='ato' size='5' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='ahsal' size='8' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='alsal' size='8' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='areason' size='45' maxlength='75'/>
                </td>
            </tr>
            <tr>
                <td>
                    <input type='text' name='bposheld' size='20' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='bcomtel' size='40' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='bimmhead' size='20' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='bfrom' size='5' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='bto' size='5' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='bhsal' size='8' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='blsal' size='8' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='breason' size='45' maxlength='75'/>
                </td>
            </tr>
            <tr>
                <td>
                    <input type='text' name='cposheld' size='20' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='ccomtel' size='40' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='cimmhead' size='20' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='cfrom' size='5' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='cto' size='5' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='chsal' size='8' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='clsal' size='8' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='creason' size='45' maxlength='75'/>
                </td>
            </tr>
            <tr>
                <td>
                    <input type='text' name='dposheld' size='20' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='dcomtel' size='40' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='dimmhead' size='20' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='dfrom' size='5' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='dto' size='5' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='dhsal' size='8' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='dlsal' size='8' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='dreason' size='45' maxlength='75'/>
                </td>
            </tr>
            <tr>
                <td>
                    <input type='text' name='eposheld' size='20' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='ecomtel' size='40' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='eimmhead' size='20' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='efrom' size='5' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='eto' size='5' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='ehsal' size='8' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='elsal' size='8' maxlength='75'/>
                </td>
                <td>
                    <input type='text' name='ereason' size='45' maxlength='75'/>
                </td>
            </tr>
            <tr>
                <td colspan="8">
                    <div align="center">
                        <input type='submit' name='Submit' id='Submit' value='Save' />
                    </div>
                </td>
            </tr>

        </form>

    </table>

1 个答案:

答案 0 :(得分:0)

使用PHP循环?一个非常简单的例子是:

$letters = array("a", "b", "c", "d", "e", "f", "g", "h");

foreach ($letters as $letter)
{
   // does one of the fields contain input
   if ($_POST[$letter.'posheld']!="" || $_POST[$letter.'comtel']!="" || $_POST[$letter.'immhead']!="" || $_POST[$letter.'from']!="" || $_POST[$letter.'to']!="") 
   {
      // process record
   }
}