【问题标题】:Birthday Registration Form Trouple生日登记表三联
【发布时间】:2014-11-11 18:52:57
【问题描述】:

您好,我正在尝试为我的网站http://social.nssgaming.com/ 制作注册表单,但注册表中有错误。我不知道出了什么问题。我不会用 3 个盒子来设置日期、月份和年份。 register.php 位于此处:http://paste2.org/a31FJE5L 您可以在此处的索引文件中设置生日部分:(这也是说它在表单中缺少一些值,我认为它在生日注册中)

<?php

function GetMonthString($n){
$timestamp = mktime(0, 0, 0, $n, 1, 2010);
return date("F", $timestamp);
}

$display .= '</select>
<select name="year" class="birthday_btn" id="year">
<option value="">- Year -</option>';

$thisyear = date('Y');
$now = $thisyear - 1;
$end = $thisyear - 100 ;

for ($now; $now >= $end; $now--) {
if ($_POST['year'] == $now){
$display .= '<option value="'.$now.'" selected>'.$now.'</option>';
}
else{
$display .= '<option value="'.$now.'" >'.$now.'</option>';
}
}
$display .= '</select> ';

$display .='</select>
<select name="month" class="birthday_btn" id="month">
<option value="" >- Month -</option>';
for ($i = 1; $i <= 12; $i++) {
if ($_POST['month'] == $i){
$display .= '<option value="'.$i.'" selected>'.GetMonthString($i).'</option>';
}
else{
$display .= '<option value="'.$i.'" >'.GetMonthString($i).'</option>';
}
}


$display .= '</select>
<select name="day" class="birthday_btn" id="day">
<option value="'.$i.'" >- Day -</option>';

for ($i = 1; $i <= 31; $i++) {
if ($_POST['day'] == $i){
$display .= '<option value="'.$i.'" selected>'.$i.'</option>';
}
else{
$display .= '<option value="'.$i.'" >'.$i.'</option>';
}
}
$display .= '</select> ';

echo $display;
?>

在本地主机中我得到了这些错误:

生日

注意:未定义变量:显示在 C:\xampp\htdocs\social\index.php 的第 237 行

注意:未定义索引:C:\xampp\htdocs\social\index.php 第 244 行中的年份

注意:未定义索引:C:\xampp\htdocs\social\index.php 第 257 行中的月份

注意:未定义索引:C:\xampp\htdocs\social\index.php 第 271 行中的日期

【问题讨论】:

标签: php


【解决方案1】:

您应该在检索值之前使用isset( $_POST['name'] ),如下所示:

$foo = null;
if( isset( $_POST['foo'] ) {
    $foo = $_POST['foo'];
}

我有自己的简单辅助函数来简化这个:

function get( $collection, $key ) {
    if( isset( $collection[ $key ] ) ) return $collection[ $key ];
    return null;
}

因此:

 $year = get( $_POST, 'year' );

【讨论】:

  • 您可以将其编辑到文档中吗?因为我不知道你到底是什么意思
猜你喜欢
  • 2014-12-13
  • 2019-07-13
  • 2017-04-30
  • 1970-01-01
  • 1970-01-01
  • 2018-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多