注意:未定义索引:使用<select> </select>时

时间:2013-11-22 20:16:57

标签: php post

好的,这就是代码

PHP:

 $rgen        = mysql_real_escape_string(strip_tags($_POST['gender']));

 $dobm        = mysql_real_escape_string(strip_tags($_POST['dobm']));
 $dobd        = mysql_real_escape_string(strip_tags($_POST['dobd']));
 $doby        = mysql_real_escape_string(strip_tags($_POST['doby']));
 $dab         = $doby.$dobm.$dobd;


 $tos         = mysql_real_escape_string(strip_tags($_POST['TOS']));  

HTML:

    <select id=ftxti name=gender style="width:130px; padding: 10px 15px; height: 52px;" >
        <option disabled selected >I'am</option>
        <option value=0 >Male</option>
        <option value=1 >Female</option>
    </select>

    <td>
</tr>

<tr>
    <td class=dob >

    <select name="dobm" id=ftxti style="width:103px;" >
        <option disabled selected >Month</option>
        <?php for ($i = 1; $i <= 12; $i++) : ?>
            <option value="<?php echo ($i < 10) ? '0'.$i : $i; ?>"><?php echo $i; ?></option>
        <?php endfor; ?>
    </select>

    <select name="dobd" id=ftxti style="width:95px;" >
        <option disabled selected >Day</option>
        <?php for ($i = 1; $i <= 31; $i++) : ?>
            <option value="<?php echo ($i < 10) ? '0'.$i : $i; ?>"><?php echo $i; ?></option>
        <?php endfor; ?>
    </select>

    <select name="doby" id=year style="width:95px;" >
        <option disabled selected >Year</option>
            <?php for ($i = 1980; $i < date('Y'); $i++) : ?>
                <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
            <?php endfor; ?>
    </select>

<label >
    <div id=tosag >
        <input type=checkbox name=TOS value=1 />
        <font style="font-size: 11px;" >
          I agree to <a href=# style="color: rgb(50, 92, 129);">TOS</a>
        </font>
    </div>
</label>

错误:

Notice: Undefined index: gender in C:\xampp\htdocs\etc\e.conf\sys.proc\proc.reg\use.register.php on line 28

Notice: Undefined index: dobm in C:\xampp\htdocs\etc\e.conf\sys.proc\proc.reg\use.register.php on line 30

Notice: Undefined index: dobd in C:\xampp\htdocs\etc\e.conf\sys.proc\proc.reg\use.register.php on line 31

Notice: Undefined index: doby in C:\xampp\htdocs\etc\e.conf\sys.proc\proc.reg\use.register.php on line 32

Notice: Undefined index: TOS in C:\xampp\htdocs\etc\e.conf\sys.proc\proc.reg\use.register.php on line 36

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\etc\e.conf\sys.proc\proc.reg\use.register.php on line 101

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\etc\e.conf\sys.proc\proc.reg\use.register.php on line 109

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\etc\e.conf\sys.proc\proc.reg\use.register.php on line 118

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\etc\e.conf\sys.proc\proc.reg\use.register.php on line 126

任何帮助将不胜感激。问题是我似乎已经定义了索引,但我必须在这里错过一个规则,我对PHP很生疏,所以请温柔地对待我,而且我也是新来的,所以如果我做错什么我很对不起...

3 个答案:

答案 0 :(得分:1)

如果没有看到所有代码,很难猜到......但我会先检查并确保您的表单方法设置为发布。

答案 1 :(得分:1)

我认为Html和Php都在同一页面。在没有提交表单的情况下加载HTML页面时,所有PHP变量都是空的。多数民众赞成就是这样。你需要以这种方式写作。

  if(isset($_POST['gender'])){
  $rgen = mysql_real_escape_string(strip_tags($_POST['gender']));
  }

另一种方式,如果你想隐藏通知&amp;警告,您可以在页面顶部添加以下代码。我不会在开发环境中建议这样做。

   error_reporting(0);
     (or) 
   ini_set( "display_errors", 0);

答案 2 :(得分:0)

这可能无法修复任何内容......但您可能认为<td></td>

    <select id=ftxti name=gender style="width:130px; padding: 10px 15px; height: 52px;" >
        <option disabled selected >I'am</option>
        <option value=0 >Male</option>
        <option value=1 >Female</option>
    </select>

    <td>   <----- This should probably be a closing tag!
</tr>

您还应该在属性周围添加引号:

<a href=#  should be <a href="#"

or

id=ftxti should be id="ftxti"

or

<option value=1 > should be <option value="1" >