设定注册限额?

时间:2013-03-23 09:26:10

标签: php mysql limit registration max

正如我已经尝试但是nodbody帮助了我,我将再次尝试。对于想要注册这个脚本的人,我想设置一个限制为16可以请某人编辑我的脚本并将其发布在这里,这样我就可以复制粘贴它,因为我在编写时非常糟糕,所以在我尝试之前总是出错PLZ有人只是简单地发布我的代码16。感谢你们,如果有人这样做会很棒

这是脚本

<?php
$error_message = "";
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
   $action = isset($_POST['action']) ? $_POST['action'] : '';
   $mysql_server = 'X';
   $mysql_username = 'X';
   $mysql_password = 'X';
   $mysql_database = 'X';
   $mysql_table = 'LOL';

   $success_page = 'X';
   if ($action == 'signup')
   {
      $newusername = $_POST['username'];
      $newemail = $_POST['email'];
      $newpassword = $_POST['password'];
      $confirmpassword = $_POST['confirmpassword'];
      $newfullname = $_POST['fullname'];
      if ($newpassword != $confirmpassword)
      {
         $error_message = 'Password and Confirm Password are not the same!';
      }
      else
      if (!ereg("^[A-Za-z0-9_!@$]{1,50}$", $newusername))
      {
         $error_message = 'Team name is not valid, please check and try again!';
      }
      else
      if (!ereg("^[A-Za-z0-9_!@$]{1,50}$", $newpassword))
      {
         $error_message = 'Password is not valid, please check and try again!';
      }
      else
      if (!ereg("^.+@.+\..+$", $newemail))
      {
         $error_message = 'Email is not a valid email address. Please check and try again.';
      }
         $db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
         mysql_select_db($mysql_database, $db);
         $sql = "SELECT username FROM ".$mysql_table." WHERE username = '".$newusername."'";
         $result = mysql_query($sql, $db);
         if ($data = mysql_fetch_array($result))
      {
         list($username, $password, $email, $fullname) = explode('|', trim($line));
         if ($newusername == $username)
         {
            $error_message = 'Team name already used. Please select another username.';
         }
      }
      if (empty($error_message))
      {
         $crypt_pass = md5($newpassword);
         $sql = "INSERT `".$mysql_table."` (`username`, `password`, `fullname`, `email`, `active`) VALUES ('$newusername', '$crypt_pass', '$newfullname', '$newemail', 1)";
         $result = mysql_query($sql, $db);
         mysql_close($db);
         $mailto = $newemail;
         $subject = 'X';
         $message = 'X';
         $message .= "\r\nX";
         $message .= "\r\n ";
         $message .= "\r\nTeam name for the upcoming tournament: ";
         $message .= $newusername;
         $message .= "\r\nYour password: ";
         $message .= $newpassword;
         $message .= "\r\n ";
         $message .= "\r\n ";
         $message .= "\r\nX";
         $message .= "\r\nX";
         $header  = "From: X"."\r\n";
         $header .= "Reply-To: X"."\r\n";
         $header .= "MIME-Version: 1.0"."\r\n";
         $header .= "Content-Type: text/plain; charset=utf-8"."\r\n";
         $header .= "Content-Transfer-Encoding: 8bit"."\r\n";
         $header .= "X-Mailer: PHP v".phpversion();
         mail($mailto, $subject, $message, $header);
         header('Location: '.$success_page);
         exit;
      }
   }
}
?>

3 个答案:

答案 0 :(得分:1)

为什么你的脚本很复杂。只要用户使用简单的计数器就可以添加1       添加,当它变为16时,只需停止脚本添加

即可

示例:

if(counter != 16)
{
 if (empty($error_message))
      {
     $counter++;
     $crypt_pass = md5($newpassword);
     $sql = "INSERT `".$mysql_table."` (`username`, `password`, `fullname`, `email`, `active`) VALUES ('$newusername', '$crypt_pass', '$newfullname', '$newemail', 1)";
     $result = mysql_query($sql, $db);
     mysql_close($db);
     $mailto = $newemail;
     $subject = 'X';
     $message = 'X';
     $message .= "\r\nX";
     $message .= "\r\n ";
     $message .= "\r\nTeam name for the upcoming tournament: ";
     $message .= $newusername;
     $message .= "\r\nYour password: ";
     $message .= $newpassword;
     $message .= "\r\n ";
     $message .= "\r\n ";
     $message .= "\r\nX";
     $message .= "\r\nX";
     $header  = "From: X"."\r\n";
     $header .= "Reply-To: X"."\r\n";
     $header .= "MIME-Version: 1.0"."\r\n";
     $header .= "Content-Type: text/plain; charset=utf-8"."\r\n";
     $header .= "Content-Transfer-Encoding: 8bit"."\r\n";
     $header .= "X-Mailer: PHP v".phpversion();
     mail($mailto, $subject, $message, $header);
     header('Location: '.$success_page);
     exit;
   }
 }

else
 {
   echo "not inserted";
 }

答案 1 :(得分:0)

<?php
$error_message = "";
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
   $action = isset($_POST['action']) ? $_POST['action'] : '';
   $mysql_server = 'X';
   $mysql_username = 'X';
   $mysql_password = 'X';
   $mysql_database = 'X';
   $mysql_table = 'LOL';

   $success_page = 'X';
   if ($action == 'signup')
   {
      $newusername = $_POST['username'];
      $newemail = $_POST['email'];
      $newpassword = $_POST['password'];
      $confirmpassword = $_POST['confirmpassword'];
      $newfullname = $_POST['fullname'];
      if ($newpassword != $confirmpassword)
      {
         $error_message = 'Password and Confirm Password are not the same!';
      }
      else
      if (!ereg("^[A-Za-z0-9_!@$]{1,50}$", $newusername))
      {
         $error_message = 'Team name is not valid, please check and try again!';
      }
      else
      if (!ereg("^[A-Za-z0-9_!@$]{1,50}$", $newpassword))
      {
         $error_message = 'Password is not valid, please check and try again!';
      }
      else
      if (!ereg("^.+@.+\..+$", $newemail))
      {
         $error_message = 'Email is not a valid email address. Please check and try again.';
      }
         $db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
         mysql_select_db($mysql_database, $db);
         $sql = "SELECT username FROM ".$mysql_table." WHERE username = '".$newusername."'";
         $result = mysql_query($sql, $db);
         if ($data = mysql_fetch_array($result))
      {
         list($username, $password, $email, $fullname) = explode('|', trim($line));
         if ($newusername == $username)
         {
            $error_message = 'Team name already used. Please select another username.';
         }
          $count=mysql_num_rows($result);
         if ($count == 16)
         {
            $error_message = 'Team Member exceeds 16';
         }

      }
      if (empty($error_message))
      {
         $crypt_pass = md5($newpassword);
         $sql = "INSERT `".$mysql_table."` (`username`, `password`, `fullname`, `email`, `active`) VALUES ('$newusername', '$crypt_pass', '$newfullname', '$newemail', 1)";
         $result = mysql_query($sql, $db);
         mysql_close($db);
         $mailto = $newemail;
         $subject = 'X';
         $message = 'X';
         $message .= "\r\nX";
         $message .= "\r\n ";
         $message .= "\r\nTeam name for the upcoming tournament: ";
         $message .= $newusername;
         $message .= "\r\nYour password: ";
         $message .= $newpassword;
         $message .= "\r\n ";
         $message .= "\r\n ";
         $message .= "\r\nX";
         $message .= "\r\nX";
         $header  = "From: X"."\r\n";
         $header .= "Reply-To: X"."\r\n";
         $header .= "MIME-Version: 1.0"."\r\n";
         $header .= "Content-Type: text/plain; charset=utf-8"."\r\n";
         $header .= "Content-Transfer-Encoding: 8bit"."\r\n";
         $header .= "X-Mailer: PHP v".phpversion();
         mail($mailto, $subject, $message, $header);
         header('Location: '.$success_page);
         exit;
      }
   }
}
?>

答案 2 :(得分:0)

如果要设置用户数限制,请在下面编写代码。

$sql = "select count(*) as tot from $mysql_table";
    $rs = mysql_query($sql);
    $row = mysql_fetch_assoc($rs);
    $counter = $row['tot'];


if(counter != 16)
{
 if (empty($error_message))
      {
     $counter++;
     $crypt_pass = md5($newpassword);
     $sql = "INSERT `".$mysql_table."` (`username`, `password`, `fullname`, `email`, `active`) VALUES ('$newusername', '$crypt_pass', '$newfullname', '$newemail', 1)";
     $result = mysql_query($sql, $db);
     mysql_close($db);
     $mailto = $newemail;
     $subject = 'X';
     $message = 'X';
     $message .= "\r\nX";
     $message .= "\r\n ";
     $message .= "\r\nTeam name for the upcoming tournament: ";
     $message .= $newusername;
     $message .= "\r\nYour password: ";
     $message .= $newpassword;
     $message .= "\r\n ";
     $message .= "\r\n ";
     $message .= "\r\nX";
     $message .= "\r\nX";
     $header  = "From: X"."\r\n";
     $header .= "Reply-To: X"."\r\n";
     $header .= "MIME-Version: 1.0"."\r\n";
     $header .= "Content-Type: text/plain; charset=utf-8"."\r\n";
     $header .= "Content-Transfer-Encoding: 8bit"."\r\n";
     $header .= "X-Mailer: PHP v".phpversion();
     mail($mailto, $subject, $message, $header);
     header('Location: '.$success_page);
     exit;
   }
 }

else
 {
   echo "not inserted";
 }