2016-06-28 36 views
0

我正在使用php和mysqli進行註冊系統。一切都很好,但是,當我把一個PHP代碼,如低於:爲什麼在從GET方法接收數據時無法在POST方法中發送數據

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

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

我的形式不再發送數據(POST方法)將數據存儲到數據庫中的遠程PHP。當我從文件中刪除GET檢查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 

行動= 「資產/ PHP /和registration.php」 方法= 「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> 

H ERE是用於存儲數據的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(); 
?> 
+0

更換你的代碼

$check = $_GET['status']; 

,這部分沒有什麼不妥提供的代碼。問題必須在其他地方。 $ _GET和$ _POST也不會互相重寫。 –

+1

表單不再發送它,或者您不再能夠從$ _POST中讀取它?這裏有兩種情況。您應該使用瀏覽器的開發人員面板檢查網絡請求,以確保表單正在發送數據。 – SArnab

+0

我給了實際的代碼。我完全失去了原因,因爲我無法找到任何問題。 – Riyadh

回答

0

也許你已經有大約在$ _GET數組未知指數 '狀態' 的錯誤。嘗試用這種

$check = isset($_GET['status']) ? $_GET['status'] : 0; 
相關問題