2015-06-29 2 views
-4

Извините за мой неправильный английский язык заранее. Я хочу подготовиться к SAT, но у меня пока нет денег, поэтому я пытаюсь сделать сайт и заработать много, прежде чем я его возьму. Я создал PHP-скрипт, но он не работает. Он отображает:PHP register script не работает как следует

Извините, но похоже, что кто-то уже использовал это письмо!

И кнопка отправки также не работает. Любая помощь будет оценена по достоинству.

signup.php:

<?php include("./inc/connect.inc.php");?> 
<?php $con = mysqli_connect("localhost", "root", "password", "NewWebsite"); 


$reg = $_POST['submit']; 

//registration form 
if (isset($reg)) { 
    $fn = $_POST['fname']; 
    $ln = $_POST['lname']; 
    $em = $_POST['email']; 
    $pswd = $_POST['pass']; 



    $e_check = mysqli_query($con,"SELECT email FROM users WHERE email='$em'"); 
//Count the number of rows returned 
    $email_check = mysqli_num_rows($e_check); 


     if ($email_check == 0) { 
//check all of the fields have been filed in 
     if ($fn && $ln && $em && $pswd) { 

// check the maximum length of username/first name/last name does not exceed 25 characters 
       if (strlen($un)>25||strlen($fn)>25||strlen($ln)>25) { 
        echo "The maximum limit for username/first name/last name is 25 characters!"; 
       } 
       else 
       { 
// check the maximum length of password does not exceed 25 characters and is not less than 5 characters 
        if (strlen($pass)>30||strlen($pass)<5) { 
         echo "Your password must be between 5 and 30 characters long!"; 
        } 
        else 
        { 
//encrypt password and password 2 using md5 before sending to database 
         $pass = md5($pswd); 
         mysqli_query($con,"INSERT INTO `NewWebsite`.`users` (`id`, `fname`, `lname`, `email`, `pass`) VALUES (NULL,'$fname', '$lname', '$email', '$pass')"); 
         die('Login to your account to get started...'); 
        } 
       } 
      } 
      else { 
       echo "Your passwords don't match!"; 
      } 
     } 
     else 
     { 
      echo "Please fill in all of the fields"; 
     } 
    } 
    else 
    { 
    echo "Sorry, but it looks like someone has already used that email!"; 
} 


?> 

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
    <title>Music and science</title> 



    <script type='text/javascript' src="http://thecodeplayer.com/uploads/js/jquery-1.9.1.min.js"></script> 



    <script type='text/javascript' src="http://thecodeplayer.com/uploads/js/jquery.easing.min.js"></script> 


    <style type='text/css'> 
    /*custom font*/ 
    @import url(http://fonts.googleapis.com/css?family=Montserrat); 

    /*basic reset*/ 
    * {margin: 0; padding: 0; 
     } 


    html { 
     height: 100%; 
     /*Image only BG fallback*/ 
     background-image: url('./Textures/signup1/footer_lodyas/footer_lodyas.png'); 
     background-repeat: repeat; 

    } 

    body { 
     font-family: montserrat, arial, verdana; 
    } 
    /*form styles*/ 
    #msform { 
     width: 400px; 
     margin: 50px auto; 
     text-align: center; 
     position: relative; 
    } 
    #msform fieldset { 
     background: white; 
     border: 0 none; 
     border-radius: 3px; 
     box-shadow: 0 0 15px 1px rgba(0, 0, 0, 0.4); 
     padding: 20px 30px; 

     box-sizing: border-box; 
     width: 80%; 
     margin: 0 10%; 

     /*stacking fieldsets above each other*/ 
     position: absolute; 
    } 
    /*Hide all except first fieldset*/ 
    #msform fieldset:not(:first-of-type) { 
     display: none; 
    } 
    /*inputs*/ 
    #msform input, #msform textarea { 
     padding: 15px; 
     border: 1px solid #ccc; 
     border-radius: 3px; 
     margin-bottom: 10px; 
     width: 100%; 
     box-sizing: border-box; 
     font-family: montserrat; 
     color: #2C3E50; 
     font-size: 13px; 
    } 
    /*buttons*/ 
    #msform .action-button { 
     width: 100px; 
     background: #27AE60; 
     font-weight: bold; 
     color: white; 
     border: 0 none; 
     border-radius: 1px; 
     cursor: pointer; 
     padding: 10px 5px; 
     margin: 10px 5px; 
    } 
    #msform .action-button:hover, #msform .action-button:focus { 
     box-shadow: 0 0 0 2px white, 0 0 0 3px #27AE60; 
    } 
    /*headings*/ 
    .fs-title { 
     font-size: 15px; 
     text-transform: uppercase; 
     color: #2C3E50; 
     margin-bottom: 10px; 
    } 
    .fs-subtitle { 
     font-weight: normal; 
     font-size: 13px; 
     color: #666; 
     margin-bottom: 20px; 
    } 
    /*progressbar*/ 
    #progressbar { 
     margin-bottom: 30px; 
     overflow: hidden; 
     /*CSS counters to number the steps*/ 
     counter-reset: step; 
    } 
    #progressbar li { 
     list-style-type: none; 
     color: white; 
     text-transform: uppercase; 
     font-size: 9px; 
     width: 33.33%; 
     float: left; 
     position: relative; 
    } 
    #progressbar li:before { 
     content: counter(step); 
     counter-increment: step; 
     width: 20px; 
     line-height: 20px; 
     display: block; 
     font-size: 10px; 
     color: #333; 
     background: white; 
     border-radius: 3px; 
     margin: 0 auto 5px auto; 
    } 
    /*progressbar connectors*/ 
    #progressbar li:after { 
     content: ''; 
     width: 100%; 
     height: 2px; 
     background: white; 
     position: absolute; 
     left: -50%; 
     top: 9px; 
     z-index: -1; /*put it behind the numbers*/ 
    } 
    #progressbar li:first-child:after { 
     /*connector not needed before the first step*/ 
     content: none; 
    } 
    /*marking active/completed steps green*/ 
    /*The number of the step and the connector before it = green*/ 
    #progressbar li.active:before, #progressbar li.active:after{ 
     background: #27AE60; 
     color: white; 
    } 


.container ul{ 
    list-style: none; 
    height: 60%; 
    width: 100%; 
    margin: 0; 
    padding: 0; 
} 


ul li{ 
    color: #AAAAAA; 
    display: block; 
    position: relative; 
    float: left; 
    width: 100%; 
    height: 60px; 

} 

ul li input[type=radio]{ 
    position: absolute; 
    visibility: hidden; 
} 

ul li label{ 
    display: block; 
    position: relative; 
    font-weight: 300; 
    font-size: 1.35em; 
    padding: 25px 25px 25px 80px; 
    margin: 1px auto; 
    height: 30px; 
    z-index: 9; 
    cursor: pointer; 
    -webkit-transition: all 0.25s linear; 
} 

ul li:hover label{ 
    color: #000; 
} 

ul li .check{ 
    display: block; 
    position: absolute; 
    border: 5px solid #AAAAAA; 
    border-radius: 100%; 
    height: 25px; 
    width: 25px; 
    top: 30px; 
    left: 20px; 
    z-index: 5; 
    transition: border .25s linear; 
    -webkit-transition: border .25s linear; 
} 

ul li:hover .check { 
    border: 5px solid #000; 
} 

ul li .check::before { 
    display: block; 
    position: absolute; 
    content: ''; 
    border-radius: 50%; 
    height: 15px; 
    width: 15px; 
    top: 5px; 
    left: 5px; 
    margin: auto; 
    transition: background 0.25s linear; 
    -webkit-transition: background 0.25s linear; 
} 

input[type=radio]:checked ~ .check { 
    border: 5px solid #0DFF92; 
} 

input[type=radio]:checked ~ .check::before{ 
    background: #0DFF92; 
} 

input[type=radio]:checked ~ label{ 
    color: #0DFF92; 
} 
    </style> 



<script type='text/javascript'>//<![CDATA[ 
window.onload=function(){ 

     /* 
    Orginal Page: http://thecodeplayer.com/walkthrough/jquery-multi-step-form-with-progress-bar 

    */ 
    //jQuery time 
    var current_fs, next_fs, previous_fs; //fieldsets 
    var left, opacity, scale; //fieldset properties which we will animate 
    var animating; //flag to prevent quick multi-click glitches 

    $(".next").click(function() { 
    if(animating) return false; 
    animating = true; 

    current_fs = $(this).parent(); 
    next_fs = $(this).parent().next(); 

     //activate next step on progressbar using the index of next_fs 
     $("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active"); 

     //show the next fieldset 
     next_fs.show(); 
     //hide the current fieldset with style 
     current_fs.animate({opacity: 0}, { 
     step: function(now, mx) { 
       //as the opacity of current_fs reduces to 0 - stored in "now" 
       //1. scale current_fs down to 80% 
       scale = 1 - (1 - now) * 0.2; 
       //2. bring next_fs from the right(50%) 
       left = (now * 50)+"%"; 
       //3. increase opacity of next_fs to 1 as it moves in 
       opacity = 1 - now; 
       current_fs.css({'transform': 'scale('+scale+')'}); 
       next_fs.css({'left': left, 'opacity': opacity}); 
      }, 
      duration: 800, 
      complete: function() { 
       current_fs.hide(); 
       animating = false; 
      }, 
      //this comes from the custom easing plugin 
      easing: 'easeInOutBack' 
     }); 
    }); 

$(".previous").click(function() { 
    if(animating) return false; 
    animating = true; 

    current_fs = $(this).parent(); 
    previous_fs = $(this).parent().prev(); 

     //de-activate current step on progressbar 
     $("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active"); 

     //show the previous fieldset 
     previous_fs.show(); 
     //hide the current fieldset with style 
     current_fs.animate({opacity: 0}, { 
     step: function(now, mx) { 
       //as the opacity of current_fs reduces to 0 - stored in "now" 
       //1. scale previous_fs from 80% to 100% 
       scale = 0.8 + (1 - now) * 0.2; 
       //2. take current_fs to the right(50%) - from 0% 
       left = ((1-now) * 50)+"%"; 
       //3. increase opacity of previous_fs to 1 as it moves in 
       opacity = 1 - now; 
       current_fs.css({'left': left}); 
       previous_fs.css({'transform': 'scale('+scale+')', 'opacity': opacity}); 
      }, 
      duration: 800, 
      complete: function(){ 
       current_fs.hide(); 
       animating = false; 
      }, 
      //this comes from the custom easing plugin 
      easing: 'easeInOutBack' 
     }); 
    }); 

$(".submit").click(function(){ 
    return false; 
}); 
}//]]> 

</script> 


</head> 
<body> 
    <form id="msform" method="POST" action"index.php"> 
     <!-- progressbar --> 
     <ul id="progressbar"> 
      <li class="active">Personal Details</li> 
      <li>Science, Guitar or Both?</li> 
      <li>Acount Setup</li> 
     </ul> 
     <!-- fieldsets --> 
     <fieldset> 
      <h2 class="fs-title">Create your account</h2> 
      <h3 class="fs-subtitle">Personal Details.</h3> 
      <input type="text" name="fname" placeholder="First Name" /> 
      <input type="text" name="lname" placeholder="Last Name" /> 

      <input type="button" name="next" class="next action-button" value="Next" /> 
     </fieldset> 
     <fieldset> 
      <h2 class="fs-title">Science or Music?</h2> 
      <h3 class="fs-subtitle">What do you like?</h3> 
      <p>Don't Worry, you can change this later..<p> 
       <div class="container"> 
        <ul> 
         <li> 
          <input type="radio" id="f-option" name="selector"> 
          <label for="f-option">Music</label> 

          <div class="check"></div> 
         </li> 

         <li> 
          <input type="radio" id="s-option" name="selector"> 
          <label for="s-option">Science</label> 

          <div class="check"> 
           <div class="inside"></div> 
          </div> 
         </li> 

         <li> 
          <input type="radio" id="t-option" name="selector"> 
          <label for="t-option">Both!</label> 

          <div class="check"> 
           <div class="inside"></div> 
          </div> 
         </li> 
        </ul> 
       </div> 


       <input type="button" name="next" class="next action-button" value="Next" /> 
      </fieldset> 
      <fieldset> 
       <h2 class="fs-title">Account Details</h2> 
       <h3 class="fs-subtitle">This is the Last Step.</h3> 
       <input type="text" name="email" placeholder="Email" /> 
       <input type="password" name="pass" placeholder="Password" /> 
       <input type="submit" name="submit" class="submit action-button" value="Submit" /> 
      </fieldset> 
     </form> 

    </body> 


    </html> 

Спасибо за любую помощь вы можете дать мне.

+0

Me onlien не один ansewr. почему никто никого. –

+0

u гордый тоже ... –

+0

as submit кнопка не работает, я не могу отправить электронное письмо. –

ответ

2
<form id="msform" method="POST" action"index.php"> 

вы пропустили «=» знак здесь

<form id="msform" method="POST" action="index.php"> 

это причина, почему страница не движется к «index.php»

+0

еще не работает –

+0

u гордый тоже ..... –

+0

Примечание: Неопределенный индекс: отправить в C: \ Apache24 \ htdocs \ NewWebsite \ Registration.php в строке 5 Извините, но выглядит как кто-то уже использовал этот адрес электронной почты! –

0

Может попробовать реорганизовать свой регистр в функцию и переупорядочивая валидацию до вершины. У вас есть переменная (ы), например $un, которые не установлены нигде, так что это приведет к отказу от проверки. Вы должны будете принести $con в функцию путем включения файла подключения или в качестве аргумента функции:

<?php 

function ValidateLength($value = false, $chars = 25) 
    { 
     if(strlen($value) <= $chars) 
      return true; 

     return false; 
    } 

function RegisterNewUser($payload = false) 
    { 
     if(!is_array($payload)) 
      return "Invalid request."; 
     // Trim empty spaces 
     foreach($payload as $key => $value) 
      $payload[$key] = trim($value); 
     // Do some basic validation here 
     $fn     = (!empty($payload['fname']))? $payload['fname']:false; 
     $ln     = (!empty($payload['lname']))? $payload['lname']:false; 
     $em     = (filter_var($payload['email'],FILTER_VALIDATE_EMAIL))? $payload['email']:false; 
     $pswd    = (!empty($payload['pass']))? $payload['pass']:false; 
     // Store values for use later 
     $storage['first'] = $fn; 
     $storage['last'] = $ln; 
     $storage['email'] = $em; 
     $storage['pass'] = $pswd; 
     // If email invalid, stop here 
     if(!$em) 
      return "Email address is invalid."; 
     // If false is in the storage array, end here. 
     if(in_array(false,$storage)) 
      return "Please fill in all of the fields"; 
     // If line length not correct, stop here 
     if(!ValidateLength($fn) || !ValidateLength($ln) || !ValidateLength($em)) 
      return "The maximum limit for username/first name/last name is 25 characters!"; 
     // If password fails length end here 
     $pass_valid  = (strlen($pass)>30||strlen($pass)<5)? true:false; 
     if(!$pass_valid) 
      return "Your password must be between 5 and 30 characters long!"; 
     // If all that other stuff passes validation check in the system 
     $e_check  = mysqli_query($con,"SELECT email FROM users WHERE email='$em'"); 
     $email_check = mysqli_num_rows($e_check); 
     // If already in system, stop here 
     if($email_check != 0) 
      return "Sorry, but it looks like someone has already used that email!"; 
     // This password encryption is unacceptable for modern day use 
     $storage['pass'] = md5($storage['pass']); 
     // Insert into database 
     mysqli_query($con,"INSERT INTO `NewWebsite`.`users` (`id`, `fname`, `lname`, `email`, `pass`) VALUES (NULL,'".implode("','",$storage)."')") 
     or die('Sorry, an error occurred'); 
     // return success 
     return true; 
    } 

if(isset($_POST['submit'])) { 
     $success = RegisterNewUser($_POST); 

     echo ($success === true)? "Login to your account to get started..." : $success; 

    } 
?> 

Как уже отмечалось ранее, исправить эту строку в виде:

<form id="msform" method="POST" action="index.php"> 
Смежные вопросы