1

私の最近のトピックの後、登録ページが最初にmysqlに挿入されていないことがわかりました。最初に、まだmysqlを使用していることを知っていますが、evrythingが機能しているときにpdoに変更します。

だからここにあります

次の部分は、データベースに挿入するために使用されています

    <div id="registerform">
    <form action="process.php" method="POST">
    <ul>
        <li>Username :
        <br />
        <?php echo $form->error("user"); ?></li>
        <li><input type="text" name="user" maxlength="30" value="<?php echo $form->value("user"); ?>"></li>
        <li>Password :
        <br />
        <?php echo $form->error("pass"); ?></li>
        <li><input type="password" name="pass" maxlength="30" value="<?php echo $form->value("pass"); ?>"></li>
        <li>Email :
        <br />
        <?php echo $form->error("email"); ?></li>
        <li><input type="text" name="email" maxlength="50" value="<?php echo $form->value("email"); ?>"></li>
        <li>First Name :<br />
        <?php echo $form->error("clan"); ?></li>
        <li><input type="text" name="clan" maxlength="30" value="<?php echo $form->value("clan"); ?>" /></li>
        <li>Last Name :<br />
        <?php echo $form->error("namers"); ?></li>
        <li><input type="text" name="namers" maxlength="30" value="<?php echo $form->value("namers"); ?>" /></li>   
        <li><input type="hidden" name="subjoin" value="1"><input type="submit" value="Register!"></li>

    </ul>
    </form>
</div>

次のコードは、

プロセス.php

   function procRegister(){
  global $session, $form;
  /* Convert username to all lowercase (by option) */
  if(ALL_LOWERCASE){
     $_POST['user'] = strtolower($_POST['user']);
  }
  /* Registration attempt */
  $retval = $session->register($_POST['user'], $_POST['pass'], $_POST['email'], $_POST['clan'], $_POST['namers']);

  /* Registration Successful */
  if($retval == 0){
     $_SESSION['reguname'] = $_POST['user'];
     $_SESSION['regsuccess'] = true;
     header("Location: ".$session->referrer);
  }
  /* Error found with form */
  else if($retval == 1){
     $_SESSION['value_array'] = $_POST;
     $_SESSION['error_array'] = $form->getErrorArray();
     header("Location: ".$session->referrer);
  }
  /* Registration attempt failed */
  else if($retval == 2){
     $_SESSION['reguname'] = $_POST['user'];
     $_SESSION['regsuccess'] = false;
     header("Location: ".$session->referrer);
  }
   }

session.php (フォームのエラーをチェック)

    function register($subuser, $subpass, $subemail, $subclan, $subnamers){
      global $database, $form, $mailer;  //The database, form and mailer object


          /* Username error checking */
          $field = "user";  //Use field name for username
          if(!$subuser || strlen($subuser = trim($subuser)) == 0){
             $form->setError($field, "* Username not entered");
      }
      else{
         /* Spruce up username, check length */
         $subuser = stripslashes($subuser);
         if(strlen($subuser) < 5){
            $form->setError($field, "* Username below 5 characters");
         }
         else if(strlen($subuser) > 30){
            $form->setError($field, "* Username above 30 characters");
         }
         /* Check if username is not alphanumeric */
         else if(!ctype_alnum($subuser)){
            $form->setError($field, "* Username not alphanumeric");
         }
         /* Check if username is reserved */
         else if(strcasecmp($subuser, GUEST_NAME) == 0){
            $form->setError($field, "* Username reserved word");
         }
         /* Check if username is already in use */
         else if($database->usernameTaken($subuser)){
            $form->setError($field, "* Username already in use");
         }
         /* Check if username is banned */
         else if($database->usernameBanned($subuser)){
            $form->setError($field, "* Username banned");
         }
      }

      /* Password error checking */
      $field = "pass";  //Use field name for password
      if(!$subpass){
         $form->setError($field, "* Password not entered");
      }
      else{
         /* Spruce up password and check length*/
         $subpass = stripslashes($subpass);
         if(strlen($subpass) < 4){
            $form->setError($field, "* Password too short");
         }
         /* Check if password is not alphanumeric */
         else if(!preg_match("/^([0-9a-z])+$/", ($subpass = trim($subpass)))){
            $form->setError($field, "* Password not alphanumeric");
         }
         /**
          * Note: I trimmed the password only after I checked the length
          * because if you fill the password field up with spaces
          * it looks like a lot more characters than 4, so it looks
          * kind of stupid to report "password too short".
          */
      }

      /* Email error checking */
      $field = "email";  //Use field name for email
      if(!$subemail || strlen($subemail = trim($subemail)) == 0){
         $form->setError($field, "* Email not entered");
      }
      else{
         /* Check if valid email address */
         if(!filter_var($subemail, FILTER_VALIDATE_EMAIL)){
            $form->setError($field, "* Email invalid");
         }
         $subemail = stripslashes($subemail);
      }
      /* First Name error checking */
      $field = "clan";      //Use field name for clan name
      if(!$subclan || strlen($subclan = trim($subclan)) == 0){
          $form->setError($field, "* Clan not entered");
      }

      /* Last Name error checking */
      $field = "namers";        //Use field name for Runescape name
      if(!$subnamers|| strlen($subnamers = trim($subnamers)) == 0){
          $form->setError($field, "* Runescape name not entered");
      }  
      /* Errors exist, have user correct them */
      if($form->num_errors > 0){
         return 1;  //Errors with form
      }
      /* No errors, add the new account to the database*/
      else{
         if($database->addNewUser($subuser, md5($subpass), $subemail, $subclan, $subnamers)){
            if(EMAIL_WELCOME){
               $mailer->sendWelcome($subuser, $subemail, $subpass, $subclan, $subnamers);
            }
            return 0;  //New user added succesfully
         }else{
            return 2;  //Registration attempt failed
         }
      }


    }

database.php (ものを挿入)

       function addNewUser($username, $password, $email, $clan, $namers){
      $time = time();
      /* If admin sign up, give admin user level */
      if(strcasecmp($username, ADMIN_NAME) == 0){
         $ulevel = ADMIN_LEVEL;
      }else{
         $ulevel = USER_LEVEL;
      }
      $q = "INSERT INTO ".TBL_USERS." VALUES ($username, $password, '0', $ulevel, $email, $time, $clan, $namers)";
      return mysql_query($q, $this->connection);
   }

次のエラーが発生しています

We're sorry, but an error has occurred and your registration for the username (name), could not be completed.
Please try again at a later time.

次のコードはそのエラー用です

    <?php
/**
 * The user is already logged in, not allowed to register.
 */
if($session->logged_in){
   echo "<h1>Registered</h1>";
   echo "<p>We're sorry <b>$session->username</b>, but you've already registered. "
       ."<a href=\"main.php\">Main</a>.</p>";
}
/**
 * The user has submitted the registration form and the
 * results have been processed.
 */
else if(isset($_SESSION['regsuccess'])){
   /* Registration was successful */
   if($_SESSION['regsuccess']){
      echo "<h1>Registered!</h1>";
      echo "<p>Thank you <b>".$_SESSION['reguname']."</b>, your information has been added to the database, "
          ."you may now <a href=\"main.php\">log in</a>.</p>";
   }
   /* Registration failed */
   else{
      echo "<h1>Registration Failed</h1>";
      echo "<p>We're sorry, but an error has occurred and your registration for the username <b>".$_SESSION['reguname']."</b>, "
          ."could not be completed.<br>Please try again at a later time.</p>";
          print_r($_SESSION);


   }
   unset($_SESSION['regsuccess']);
   unset($_SESSION['reguname']);
}

問題は、彼がデータベースに何も挿入しないことです

たくさんのコードかもしれませんが、これで十分な情報が得られることを願っています

4

1 に答える 1

7

INSERT クエリでは、VALUES の varchar に引用符が必要です。

$q = "INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '0', '$ulevel', '$email', '$time', '$clan', '$namers')";
于 2013-07-25T15:08:06.127 に答える