为什么我不能在从GET方法

时间:2016-06-28 20:32:21

标签: php

我正在使用php和mysqli进行注册系统。一切都很好,但是当我输入一个PHP代码,如下所示:

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

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

我的表单不再向远程php发送数据( 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

行动=&#34;资产/ PHP /和registration.php&#34;方法=&#34; POST&#34; ENCTYPE =&#34; text / plain的&#34;&GT;

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();
?>

1 个答案:

答案 0 :(得分:0)

可能您有关于未知索引&#39;状态&#39;的错误在$ _GET数组中。尝试替换代码的这一部分

$check = $_GET['status'];

用这个

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