用户在提交表单后每次刷新页面时都会注册[重复]

问题描述 投票:-2回答:1

我正在使用PHP进行注册过程。我设法获取提交的表单数据并将其保存到mysql表中,但问题是,如果我刷新页面,用户会再次注册。这是我的PHP代码,我已将其包含在带有其他内容的div标记中:

<?php
    if(isset($_POST["registration"])){
            $con = mysqli_connect("localhost", "user", "pass", "name") or die("connection error");
      if (mysqli_connect_errno()){
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }

      $name = $_POST["name"];
      $lname = $_POST["lname"];
      $email = $_POST["email"];
      $pass = $_POST["pass"];
      $company = $_POST["company"];
      $webpage = $_POST["webpage"];
      $phone = $_POST["phone"];
      $country = $_POST["country"];
      $city = $_POST["city"];
      date_default_timezone_set('Asia/Tbilisi');
      $info = getdate();
      $date = $info['mday'];
      $month = $info['mon'];
      $year = $info['year'];
      $hour = $info['hours'];
      $min = $info['minutes'];
      $sec = $info['seconds'];
      $reg_date = $year . "-" . $month . "-" . $date . " " . $hour . ":" . $min . ":" . $sec;
      $confirmed = "0";
      $success = mysqli_query($con, "INSERT INTO users(firstname, lastname, email, pass, company, webpage, country, city, phone, reg_date, confirmed) VALUES('$name','$lname','$email', '$pass', '$company', '$webpage', '$country', '$city', '$phone', '$reg_date', '$confirmed')");
      if($success){
            echo "You have been successfully registered. Use the form above to log in.";
        }
        else{
            echo "registration error";
        }
      //unset($_POST["registration"]);
    }
  ?>

我也试图取消你所看到的$_POST["registration"],但它没有帮助。我该怎么做才能使这个代码仅在单击“注册”按钮时工作?

附:我在页面的开头开始会话,但没有为其分配任何数据。

php registration
1个回答
5
投票

成功时将用户重定向到另一个URL

header('Location: '. $url);
die();
© www.soinside.com 2019 - 2024. All rights reserved.