-3

正如我已经尝试过但 nodbody 帮助了我,我会再试一次。我想为想要注册此脚本的人设置一个限制为 16 可以请有人编辑我的脚本并将其发布在这里以便我可以复制粘贴它因为我在编码方面非常糟糕所以在我尝试之前总是会出错请有人只是简单地用 limt 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;
      }
   }
}
?>
4

3 回答 3

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";
 }
于 2013-03-23T09:48:52.050 回答
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";
 }
于 2013-03-23T10:06:20.950 回答
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;
      }
   }
}
?>
于 2013-03-23T09:35:16.600 回答