PHP,MySQL注册表单

时间:2014-01-13 21:04:28

标签: php mysql

    <?php
    error_reporting (E_ALL ^ E_NOTICE);
    ini_set('display_errors','1');
    session_start();
    ?>
    <?php

    if (isset($_POST['signupbtn'])) {
    $firstname = $_POST['first_name'];
    $lastname = $_POST['last_name'];
    $email = $_POST['email'];
    $country = $_POST['country'];
    $state = $_POST['state'];
    $city = $_POST['city'];
    $address = $_POST['address'];
    $gender = $_POST['gender'];
    $zip = $_POST['zip'];
    $phone = $_POST['phone'];
    $pass = $_POST['pass'];
    $retypepass = $_POST['retypepass'];

    if ($firstname) {

    }
    else
    $echoFirstName = "You must enter your first name";

    if ($lastname) {

    }
    else
      $echoLastName = "You must enter your last name";

      if ($email) {
        if ( (strlen($email) >= 7 && (strstr($email, "@")) && (strstr($email, ".")))){
          require("../php/connect.php");
          if ($numrows == 0){
            $query = mysql_query("SELECT * FROM users WHERE email='$email'");
              $numrows = mysql_num_rows($query);
              mysql_close();

          }
          else
            $echoEmailExists = "This email already exists";

        }
        else
          $echoInvalidEmail = "You must enter a valid email address";
      }
      else
        $echoEmail = "You must enter your email address";

        if ($country) {

        }
        else
          $echoCountry = "You must select your country";

          if ($state) {

          }
          else
            $echoState = "You must enter your state";

            if ($city) {

            }
            else
              $echoCity = "You must enter your city";

              if ($address) {
                require("../php/connect.php");
                if ($numrows == 0){
                  $query = mysql_query("SELECT * FROM users WHERE address='$address'");
                    $numrows = mysql_num_rows($query);
                    mysql_close();
                }
                else
                  $echoAddressExists = "This address already exists";

              }
              else
                $echoAddress = "You must enter your address";

                if ($gender) {

                }
                else
                  $echoGender = "You must select your gender";

                  if ($zip) {

                  }
                  else
                    $echoZip = "You must enter your zip code";

                    if ($phone) {
                      require("../php/connect.php");
                      if ($numrows == 0){
                          $query = mysql_query("SELECT * FROM users WHERE phone='$phone'");
                            $numrows = mysql_num_rows($query);
                            mysql_close();
                      }
                      else
                        $echoPhoneExists = "This phone number already exists";
                    }
                    else
                      $echoPhone = "You must enter your phone number";

                      if ($pass) {
                        if ($retypepass) {
                          if ( $pass === $retypepass ){
                            require("../php/connect.php");

                                    $cryptpass = crypt($pass);
                                      include_once ("../php/randStrGen.php");
                                      $pass_hash =                     randStrGen(20)."$cryptpass".randStrGen(20);
                                      $date = date("F d, Y");
                                      $code = md5(rand());

                                      mysql_query("INSERT INTO users VALUES (
                                          '', '$firstname', '$lastname', '$email', '$country', '$state', '$city', '$address', '$gender', '$zip', '$phone', '$pass_hash', '0', '$date', '$code'
                                      )");

                                    if ($numrows == 1){

                                      $site = "http://stripemovies.tk";
                                      $webmaster = "noreply <noreply@dghosting.net>";
                                      $headers = "From: $webmaster";
                                      $headers .= "MIME-Version: 1.0\r\n";
                                      $headers .= "Content-Type: text/html; charset=utf-8";
                                      $subject = "Activate Your Stripe Movies Account";
                                      $message = "Tak fordi at du har registreret dig. Klik på linket nedenunder for at aktivere din konto.\n";
                                      $message .= "$site/activation/?fn=" . $firstname . "&ln=" . $lastname . "&p=" . $pass_hash . "&e=" . $email . "";

                                      if (mail($email, $subject, $message, $headers) ){
                                      $echoRegistered = "<div class='form-side-info'><p><font color='red'>* </font>Du er blevet registreret. Du skal aktivere din konto fra aktiveringslinket sendt til <b>$email</b>.<br />Lad det tage 5 minutter at nå frem, ellers tjek din spam mappe</p></div>";
                                      $email = "";

                                      }
                                      else
                                        $echoFailEmail = "<font color='red'>* <span>Your activation link was not sent</span></font>";

                                    }
                                    else
                                      $echoFailRegister = "<font color='red'>* <span>Your account has not been created</span></font>";
                                    mysql_close();

                          }
                          else
                            $echoInvalidPass = "Your passwords does not match";

                        }
                        else
                          $echoRetypePass = "You must confirm your password";

                      }
                      else
                        $echoPass = "You must enter your password";




    }
    ?>
<!DOCTYPE html PUBLIC "-//W3C//DD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
        <head>
        <meta charset="utf-8">
<title>Stripe Movies - Sign Up</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width">

        <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
        <link href="http://stripemovies.tk/assets/theme_venera.css" media="all" rel="stylesheet" type="text/css" />
        <link href="http://fonts.googleapis.com/css?family=Abel:400|Oswald:300,400,700" media="all" rel="stylesheet" type="text/css" />
        <meta content="authenticity_token" name="csrf-param" />
    <meta content="mcZQqRYWJr6dSGKE58lcmAA7hTBr7jwlE5wmc5oz3kY=" name="csrf-token" />
    <link href="http://stripemovies.tk/fonts/css/font-awesome.css" rel="stylesheet" type="text/css">

  </head>
    <body>


<!--[if lt IE 7]>
        <p class="chromeframe">You are using an outdated browser. <a href="http://browsehappy.com/">Upgrade your browser today</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to better experience this site.</p>
    <![endif]-->
        <?php require("../header.php"); ?>



        <section class='section-wrapper create-account-page-w'>
    <div class='container'>
    <div class='row'>
    <div class='span9'>
    <div class='white-card extra-padding'>
    <form action="http://stripemovies.tk/signup/index-2.php" method="post">
    <fieldset>
    <div class='row-fluid'>
    <div class='span12'>

    <h1 class='form-header'>Create Account</h1>

</div>
</div>
<div class='row-fluid'>
<div class='span12'>
<?php echo $echoRegistered; ?>
</div>
</div>
<div class='row'>
<div class='span4'>
<div class='control-group'>
<label>First Name <font color="red">* <span><?php echo $echoFirstName; ?></span></font></label>
<input class='span4' placeholder='Your first name...' type='text' name='first_name' value="<?php echo $firstname; ?>">
</div>
</div>
<div class='span4'>
<div class='control-group'>
<label>Last Name <font color="red">* <span><?php echo $echoLastName; ?></span></font></label>
<input class='span4' placeholder='Your last name...' type='text' name='last_name' value="<?php echo $lastname; ?>">
</div>
</div>
</div>
<div class='row'>
<div class='span4'>
<div class='control-group'>
<label>Email Address <font color="red">* <span><?php echo $echoEmail; ?><?php echo $echoInvalidEmail ?><?php echo $echoEmailExists; ?></span></font></label>
<input class='span4' placeholder='Your email address...' type='text' name='email' value="<?php echo $email; ?>">
</div>
</div>
<div class='span4'>
<div class='control-group'>
<label>Country  <font color="red">* <span><?php echo $echoCountry; ?></span></font></label>
<?php include("countries.php"); ?>
</div>
</div>
</div>
<div class='row'>
<div class='span4'>
<div class='control-group'>
<label>State <font color="red">* <span><?php echo $echoState; ?></span></font></label>
<input class='span4' placeholder='Your state...' type='text' name='state' value="<?php echo $state; ?>">
</div>
</div>
<div class='span4'>
<div class='control-group'>
<label>City <font color="red">* <span><?php echo $echoCity; ?></span></font></label>
<input class='span4' placeholder='Your city...' type='text' name='city' value="<?php echo $city; ?>">
</div>
</div>
</div>
<div class='row'>
<div class='span4'>
<div class='control-group'>
<label>Address <font color="red">* <span><?php echo $echoAddress; ?><?php echo $echoAddressExists; ?></span></font></label>
<input class='span4' placeholder='Your address...' type='text' name='address' value="<?php echo $address; ?>">
</div>
</div>
<div class='span4'>
<div class='control-group'>
<label>Gender <font color="red">* <span><?php echo $echoGender; ?></span></font></label>
<select name='gender'>
<option value="<?php if ($gender){ echo $gender;} else echo $gender; ?>"><?php if ($gender){ echo $gender;} else echo "Select your gender"; ?></option>
<option value='m'>Male</option>
<option value='f'>Female</option>
</select>
</div>
</div>
</div>
<div class='row'>
<div class='span4'>
<div class='control-group'>
<label>Zip Code <font color="red">* <span><?php echo $echoZip; ?></span></font></label>
<input class='span4' placeholder='Your zip code...' type='text' name='zip' value="<?php echo $zip; ?>">
</div>
</div>
<div class='span4'>
<div class='control-group'>
<label>Phone Number <font color="red">* <span><?php echo $echoPhone; ?><?php echo $echoPhoneExists; ?></span></font></label>
<input class='span4' placeholder='Your phone number with country code...' type='text' name='phone' value="<?php echo $phone; ?>">
</div>
</div>
</div>
<div class='row'>
<div class='span4'>
<div class='control-group'>
<label>Password <font color="red">* <span><?php echo $echoPass; ?><?php echo $echoInvalidPass; ?></span></font></label>
<input class='span4' placeholder='Your password...' type='password' name='pass' value="<?php if($pass === $retypepass){ echo $pass;} elseif ($pass){ echo $pass;} ?>">
</div>
</div>
<div class='span4'>
<div class='control-group'>
<label>Confirm Password <font color="red">* <span><?php echo $echoRetypePass; ?><?php echo $echoInvalidPass; ?></span></font></label>
<input class='span4' placeholder='Password confirmation...' type='password' name='retypepass' value="<?php if($pass === $retypepass){ echo $retypepass;} ?>">
</div>
</div>
</div>
<div class='row-fluid'>
<div class='span12'>
<div class='form-actions no-margin-bottom'>
<button class="btn btn-primary btn-large" name="signupbtn" type="submit">Complete Registration</button><?php echo $echoFailRegister; ?><?php echo $echoFailEmail; ?>
</div>
</div>
</div>
</fieldset>
</form>
</div>
</div>
<div class='span3'>
<div class='blog-side-text-block widget-filled widget-yellow'>
<h3>Some Tips:</h3>
<ul class='big-iconed-tips'>
<li>
<i class='icon-credit-card'></i>
Registration is free
</li>
<li>
<i class='icon-lock'></i>
100% Secured
</li>
<li>
<i class='icon-comments'></i>
24 Hours online support
</li>
<li>
<i class='icon-cogs'></i>
Customizable
</li>
<li>
<i class='icon-github'></i>
Host it on github
</li>
</ul>
<p>Ut diam arcu, dictum ut vulputate sed, iaculis nec lorem. Fusce pharetra nisl vitae nisl ultricies ut malesuada leo fringilla.</p>
</div>
</div>
</div>
</div>
</section>

<?php require("../footer.php"); ?>
</body>

</html>

我的问题是,当我注册时(即使字段没有正确填写)我仍然可以注册,如果电子邮件与mysql数据库中的电子邮件相同,则相同。 如果细节是正确的,它就会反映出帐户尚未创建,即使它已经创建了。

0 个答案:

没有答案