php - 尝试使用 php 检查 html 文本框是否为空

标签 php mysql html

我有这段代码来验证 html 文本框是否为空。但我不明白入场时间和地址有什么共同点,它们似乎不起作用。即使我在其中输入了数据,代码也不会读取它们:

   <html>
<head>
<title>Admission Information Sheet</title>
    <meta http-equiv="Content-Type" content="text/html; Western (ISO-8859-1)">
    <meta name="author" content=" ">
<title>
<style>
input { font-size: 16px;}
</style>
<?php include('header.php'); ?>
<div id="main_content">

</div>
<?php include('footer.php'); ?>

<table border="1" width="900" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1.1" method="POST" action="aisaction.php">

<?php

     $TELNUM = $_POST[telnum];
     $HOSPNUM = $_POST[hnum];
     $ROOMNUM = $_POST[rnum];
     $LASTNAME = $_POST[lname];
     $FIRSTNAME = $_POST[fname];
     $MIDNAME = $_POST[mname];
     $ADDRESS = $_POST[address];
     $NURSE = $_POST[nurse];

     $ADATE = $_POST[adate];
     $ADTIME = $_POST[adtym];
     $CSTAT = $_POST[cs];
     $AGE = $_POST[age];
     $BDAY = $_POST[bday];
     $SEX = $_POST[sex];


     ?>
<td>
<table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="12" style="background:#9ACD32; color:white; border:white 1px solid; text-align: center"><strong><font size="3">ADMISSION INFORMATION SHEET</strong></td>
</tr>
<tr>


</td><br>     
<td width="54"><font size="3">Hospital #</td>
<td width="3">:</td>
<td width="168"><input type="display" name="hnum" disabled="true" value= "<?php print "$HOSPNUM";?>"><br>
         <font color="red">     
     <?php   
        if(empty($HOSPNUM))
            print "* Hospital Number required!<br>";
    ?>
</td>

<td width="41"><font size="3">Room #</td>
<td width="3">:</td>
<td width="168"><input type="display" name="rnum" disabled="true" value= "<?php print "$ROOMNUM";?>"><br>
        <font color="red">      
     <?php
            if(empty($ROOMNUM ))
            print "* Room Number required!<br>";
     ?>
</td>

<td width="67"><font size="3">Admission Date</td>
<td width="3">:</td>
<td width="168"><input type="display" name="adate" disabled="true" value= "<?php print "$ADATE";?>"><br>
        <font color="red">      
     <?php
            if(empty($ADATE))
            print "* Admission Date required!<br>";
     ?>
</td>

</tr>
<tr>
<td><font size="3">Last Name</td>
<td>:</td>
<td><input type="display" name="lname" disabled="true" value= "<?php print "$LASTNAME";?>"><br>
        <font color="red">      
     <?php
            if(empty($LASTNAME))
            print "* Last Name required!<br>";
     ?>
</td>
<td><font size="3">First Name</td>
<td>:</td>
<td><input type="display" name="fname" disabled="true" value= "<?php print "$FIRSTNAME";?>"><br>
        <font color="red">      
     <?php
            if(empty($FIRSTNAME))
            print "* First Name required!<br>";
     ?>
</td>
<td><font size="3">Middle Name</td>
<td>:</td>
<td><input type="display" name="mname" disabled="true" value= "<?php print "$MIDNAME";?>"><br>
        <font color="red">      
     <?php
            if(empty($MIDNAME))
            print "* Middle Name required!<br>";
     ?>
</td>
<td width="67"><font size="3">Admission Time</td>
<td width="3">:</td>
<td width="168"><input type="display" name="adtym" disabled="true" value= "<?php print "$ADTIME";?>"><br>
        <font color="red">      
     <?php
            if(empty($ADTIME))
            print "* Admission Time required!<br>";
     ?>
</td>
</tr>



<tr>
<td><font size="3">Civil Status</td>
<td>:</td>
<td><input type="display" name="cs" disabled="true" value= "<?php print "$CSTAT";?>"><br>
        <font color="red">      
     <?php
            if(empty($CSTAT))
            print "* Civil Status required!<br>";
     ?>
</td>
<td><font size="3">Age</td>
<td>:</td>
<td><input type="display" name="age" disabled="true" value= "<?php print "$AGE";?>"><br>
        <font color="red">      
     <?php
            if(empty($AGE))
            print "* Age required!<br>";
     ?>
</td>
<td><font size="3">Birthday</td>
<td>:</td>
<td><input type="display" name="bday" disabled="true" value= "<?php print "$BDAY";?>"><br>
        <font color="red">      
     <?php
            if(empty($BDAY))
            print "* Birthday required!<br>";
     ?>
</td>

</tr>

<tr>
<td><font size="3">Address</td>
<td>:</td>
<td><input type="display" name="address" disabled="true" value= "<?php print "$ADDRESS";?>"><br>
        <font color="red">      
     <?php
            if(empty($ADDRESS))
            print "* Address required!<br>";
     ?>
</td>
<td><font size="3">Telephone #</td>
<td>:</td>
<td><input type="display" name="telnum" disabled="true" value= "<?php print "$TELNUM";?>"></td>
    <font color="red">      
     <?php
            if(empty($TELNUM))
            print "* Address required!<br>";
     ?>


<td width="23"><font size="3">Sex</td>
<td width="3">:</td>
<td width="174"><input type="display" name="sex" disabled="true" value= "<?php print "$SEX";?>"><br>
        <font color="red">      
     <?php
            if(empty($SEX))
            print "* Gender required!<br>";
     ?>
</td>
</tr>

<tr>
<td><font size="3">Pls. Check</td>
<td>:</td>
<td><input name="stats1" type="checkbox" id="SSS" value="SSS">SSS</td>
<td><font size="3"></td>
<td>:</td>
<td><input name="stats1" type="checkbox" id="nonmed" value="NonMedicare">Non Medicare</td>

<td><font size="3"></td>
<td>:</td>
<td><input name="stats1" type="checkbox" id="sh" value="stockholder">Stockholder</td>
</tr>


<tr>
<td><font size="3"></td>
<td></td>
<td><input name="stats1" type="checkbox" id="gsis" value="GSIS">GSIS</td>
<td><font size="3"></td>
<td></td>
<td><input name="stats1" type="checkbox" id="senior" value="seniorcitizen">Senior-Citizen</td>


<tr>
<td><font size="3"></td>
<td></td>
<td><input name="stats1" type="checkbox" id="dep" value="dependent">Dependent</td>
<td><font size="3"></td>
<td></td>
<td><input name="stats1" type="checkbox" id="emp" value="employee">Employee</td>

</tr>

<tr>
<td><font size="3">Attending Nurse</td>
<td>:</td>
<td><input type="display" name="nurse" disabled="true" value= "<?php print "$NURSE";?>"><br>
        <font color="red">      
     <?php
            if(empty($NURSE))
            print "* Admitting/Attending Nurse required!<br>";
     ?>
</td>


</tr>


<tr>

<td>&nbsp;</td>
<td>&nbsp;</td>

<td><input type="button" value="Back" onClick="history.go(-1);return true;">
<?php
        $val1 = $_POST['NURSE'];
        if($_POST['NURSE'] != "")
        {
    ?>
    <form action="aisaction.php" method="POST" target="_window">
            <input type="hidden" name="submit" value="yes">
            <input type="submit" value="submit">
    </form>
    <?php
        }
    ?>

</td>
</td>

</tr>
</table>
</td>


</form>
</tr>
</table>
</head>
</html>

最佳答案

第二个怎么了 <form>只包含一个隐藏的输入和一个提交按钮?该提交按钮属于外部表单。 (无论如何,表单不能嵌套。表单不能嵌套在其他表单内!)

做这个:

<form action="aisaction.php" method="POST" target="_window">
    <input type="hidden" name="submit" value="yes">
    <input type="submit" value="submit">
</form>

进入此:

<input type="hidden" name="submit" value="yes">
<input type="submit" value="submit">

关于php - 尝试使用 php 检查 html 文本框是否为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2346678/

相关文章:

php - PHP 的 $_FILES 是否在服务器上重复使用文件名?

php - 既然 copydb 已弃用,如何使用 PHP 复制 MongoDB 数据库

php - htaccess 检查查询字符串是否为空

php - MySQL 1253 COLLATION 错误 PHP

mysql - 从范围中选择最大值

python - 在python中调用数据库时如何判断高度是否重复 第一个打印具有较小权重的行?

javascript - 单击关闭时如何制作 <ul> 列表 "retract"

php - <链接rel ="canonical"href ='<?=$slink?>' >

html - 如何更改 SharePoint RichHtmlField 中的段落格式

php - 在 PHP 中迭代复杂的关联数组