生日登记表格麻烦

时间:2014-10-17 21:44:28

标签: php jquery mysql forms date

你好,我试图为我的网站http://social.nssgaming.com/制作一个注册表格,但我在注册表格中收到了错误。而且我不知道什么是错的。我不会在3个盒子里你可以看到日期,蛾子和年份。 register.php位于:http://paste2.org/a31FJE5L 您可以在索引文件中查看生日的一部分:

<?php include("php_includes/registration.php"); ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Social Nssgaming</title>
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="http://social.nssgaming.com/style/index/index.css">
<link rel='stylesheet' href='http://social.nssgaming.com/style/header/global.css' />
<script>
function emptyElement(x){
_(x).innerHTML = "";
}
function checkusername(){
var u = _("username").value;
if(u != ""){
    _("username_check").innerHTML = '<strong style="color:#3CF;">Checking database...      </strong>';
    var ajax = ajaxObj("POST", "index.php");
    ajax.onreadystatechange = function() {
        if(ajaxReturn(ajax) == true) {
            _("username_check").innerHTML = ajax.responseText;
        }
    }
    ajax.send("usernamecheck="+u);
}
}
function signup(){
var fn = _("firstname").value;
var ln = _("lastname").value;
var u = _("username").value;
var e1 = _("email1").value;
var e2 = _("email2").value;
var p1 = _("pass").value;
var p2 = _("pass2").value;
var c = _("country").value;
var g = _("gender").value;
var l = _("location").value;
var day = _("day").value;
var month = _("month").value
var year = _("year").value;
var bd = $_POST['month'];
var message = _("message");
if(u == "" || e1 == "" || e2 == "" || p1 == "" || p2 == "" || c == "" || g == "" || l  == "" || fn == "" || ln == "" || bd == ""){
    message.innerHTML = "Fill out all of the form data";
} else if(e1 != e2){
    message.innerHTML = "The email fields do not match";
} else if(p1 != p2){
    message.innerHTML = "The password fields do not match";
} else {
    _("signupbtn").style.display = "none";
    message.innerHTML = 'Please wait ...';
    var ajax = ajaxObj("POST", "index.php");
    ajax.onreadystatechange = function() {
        if(ajaxReturn(ajax) == true) {
            if(ajax.responseText != "signup_success"){
                message.innerHTML = ajax.responseText;
                _("signupbtn").style.display = "block";
            } else {
                window.scrollTo(0,0);
                _("signupform").innerHTML = "OK "+u+", check your email inbox and junk mail box at <u>"+e+"</u> in a moment to complete the sign up process by activating your account. You will not be able to do anything on the site until you successfully activate your account.";
            }
        }
    }
    ajax.send("u="+u+"&e="+e1+"&p="+p1+"&c="+c+"&g="+g+"&l="+l+"&fn="+fn  +"&ln="+ln+"&fn="+fn+"&bd="+bd);
}
}
</script>
</head>
<div id="custom_alert_overlay"></div>
<div id="custom_alert_box" style="width: 350px; background: #F6F6F6;">
<div>
<div id="dialogboxhead"></div>
<div id="dialogboxbody" style="background: #F6F6F6;">
</div>
</div>
</div>
<body style="margin: 0px; padding: 0px; font-family: 'PT Sans'; font-size: 14px;     background: #f4f4f4;">
<?php include_once("navigation_offline.php"); ?>
<div class="frontpage_wrapper">
<div class="frontpage_center">
  <span id="message"></span>
  <div id="about">
    <?php include_once("template_about.php"); ?>
  </div>
  <form name="signupform" id="signupform" onsubmit="return false;">
    <h2>Sign Up Here!</h2>
    <div id="input_center">
    <input type="text" name="firstname" size="25" placeholder="First Name" onfocus="emptyElement('message')" id="firstname" autocomplete="off" maxlength="50"/><br />  <br />
    <input type="text" name="lastname" size="25" placeholder="Last Name" onfocus="emptyElement('message')" id="lastname" autocomplete="off" maxlength="50"/><br /> <br />
    <input type="text" name="username" size="25" placeholder="Username" onfocus="emptyElement('message')" id="username" autocomplete="off" onblur="checkusername()" onkeyup="restrict('username')" maxlength="25"/>
    <span id="username_check"></span><br /><br />
    <input type="email" name="email" size="25" placeholder="Email" onfocus="emptyElement('message')" id="email1" autocomplete="off" maxlength="88"/><br /><br />
    <input type="email" name="confirm_email" size="25" placeholder="Confirm email" onfocus="emptyElement('message')" id="email2" autocomplete="off" maxlength="88"/><br /><br />
    <input type="password" name="password" size="25" placeholder="Password" onfocus="emptyElement('message')" autocomplete="off" maxlength="100" id="pass"/><br /><br />
    <input type="password" name="confirm_password" size="25" placeholder="Confirm password" onfocus="emptyElement('message')" autocomplete="off" maxlength="100" id="pass2"/><br /><br />
    <input type="text" name="location" size="25" placeholder="Location" onfocus="emptyElement('message')" id="location" autocomplete="off" maxlength="30"/><br />
    </div>
    <div id="birthday_container">
    <p class="subtitleparagraf_front">Birthday</p>
<?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;
?>
    </div>
    <div id="sex_container">
      <input type="radio" name="gender" value="m" id="gender" checked  onfocus="emptyElement('message')">Male 
      <input type="radio" name="gender" value="f" id="gender" onfocus="emptyElement('message')">Female 
    </div>
    <div id="input_center">
    <select id="country" onfocus="emptyElement('message')" autocomplete="off">
      <?php include_once("template_country_list.php"); ?>
    </select><br /><br />
    <input type="button" id="signupbtn" onclick="signupEvent();" value="Create   Account!">
    </div>
    <div id="terms_container">By clicking "Create Account!" you agree with our terms of use!</div>
  </form>
</div>

我希望你能帮助我。

1 个答案:

答案 0 :(得分:0)

我认为以下内容会有所帮助:

错误是你使用了一个&#34;未定义的函数,而你实际上已经声明了你的函数GetMonthString()。但是你引用它之后就宣布了这个功能。因此,自上而下执行的代码(至少对于变量而言)将找不到您的函数。最简单的解决方案是在调用函数之前尝试定义函数。像这样:

<?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;
    ?>

(抱歉,额外的标签,代码的一半;)。

希望这会对你有帮助!