簡體   English   中英

為什么在從GET方法接收數據時不能以POST方法發送數據

[英]Why can't I send Data in POST method while receiving data from GET method

我在用php和mysqli創建注冊系統。 一切都很好,但是當我放入一個PHP代碼時,如下所示:

<?php 
$check = $_GET['status'];

if ($check == '1') {
  //Do something
}
else{
        //Do something
            }
 ?>

我的表單不再將數據( POST方法)發送到將數據存儲到數據庫的遠程php。 當我從文件中刪除GET check php代碼時,它工作正常,但是我需要檢查需要使用它的注冊系統的狀態。

編輯:

實際代碼

<?php
$check = $_GET['status'];

$default  = "Please enter the requried information below.";
$error = "<strong>We are sorry but something went wrong. please <a href=\"contact.php\">click here</a> to let us know. We will look up to the mater as soon as possible and will let you know.</strong>";
$exist ="The College ID that you have provided is already registered. If you think this is a mistake or someone else register with your ID then please let us know <a href=\"contact.php\">here</a>.";
if ($check == 'error') {
  $output = $error;
  $alert = 'danger';
}
else{
        if($check == 'exist'){
                $output = $exist;
                $alert = 'warning';
            }
            else{
                $output = $default;
                $alert = 'info';
         }
    }
?>

實際的表單代碼:

<form

action =“ assets / php / registration.php” method =“ POST” enctype =“ text / plain”>

Name: <input type="text" class="form-control" id="name" name="name" placeholder="Enter name" required autofocus />

Email: <input type="email" class="form-control" id="email" name="email" placeholder="Enter email" required />
Phone: <input type="number" class="form-control" id="id"  name="phone" min="0000000000" max="9999999999" placeholder="College ID" required />
Current ID: <input type="text" class="form-control" id="id" min="1000000" max="2000000" name="id" placeholder="College ID" required  />
Current Section: <select id="subject" name="section" class="form-control" required="required">
  <option value="Not Specified" selected="">Choose One:</option>
  <option value="A">A</option>
  <option value="B">B</option>
</select>

<input type="checkbox" name="accept" value="accept" style="margin-right: 5px;" required="required"> I accept the <a href="#" data-toggle="modal" data-target="#myModal">term an policy</a> regarding the club.

<button type="submit" class="btn btn-primary" id="btnContactUs">Become a Member</button>
</form>

這是用於存儲數據的php:

 <?php
 Include('connect.php');

$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$id = $_POST['id'];
$section = $_POST['section'];
$ip = $_SERVER['REMOTE_ADDR'];

// Create connection
$con = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);

}

$query = mysqli_query($con, "SELECT * FROM member_registration WHERE email = '".$email. "'");
if(mysqli_num_rows($query) > 0){
header('Location: ../../..get_involved.php?status=exist');
}else{

$query = mysqli_query($con, "SELECT * FROM member_registration WHERE college_id = '".$id. "'");

if(mysqli_num_rows( $query) > 0){
header('Location: ../../get_involved.php?status=exist');
}else{

$sql = "INSERT INTO member_registration (name, email, phone_no, college_id, section, ip_address)
VALUES ('$name', '$email', '+880$phone', '$id', '$section', '$ip')";
if ($con->query($sql) === TRUE) {
    header('Location: ../../get_involved.php?status=success');
    } 
  }
}

$con->close();
?>

可能您在$ _GET數組中遇到了有關未知索引“狀態”的錯誤。 嘗試替換代碼的這一部分

$check = $_GET['status'];

有了這個

$check = isset($_GET['status']) ? $_GET['status'] : 0;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM