birthday registration form trouble

2019-09-07 13:56发布

问题:

hello I'm trying to make a registration form for my website http://social.nssgaming.com/ but i got a error in the registration form. and i don't know what's wrong. i wont 3 boxes where you can se date, moth, and year. register.php is located here: http://paste2.org/a31FJE5L you can se the part of birthday in the index file here:

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

i hope you can help me.

回答1:

I think the following will help:

The error is that you use an "undefined function, while you actually have declared your function, GetMonthString(). But you've declared the function AFTER you refer to it. So the code, which is executed top-down(at least for the variables), will not find your function. The easiest solution is to try to define the function before calling it. Like this:

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

(Sorry for the extra tab, halfway the code ;).

Hope this will help you!