Riyadh Riyadh - 1 year ago 64
PHP Question

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

I was making on a registration system with php and mysqli. Everything was fine but when I put a php code, such as below:

$check = $_GET['status'];

if ($check == '1') {
//Do something
//Do something

My form is no longer sending data (POST method) to the remote php which stores the data to a database. When I remove the GET check php code from the file it works fine, but I need to check the status of the registration system for which I need to use it.


The actual code

$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';
if($check == 'exist'){
$output = $exist;
$alert = 'warning';
$output = $default;
$alert = 'info';

The actual form code:


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>

<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>

Here is the php for storing the data:


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

// 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');

$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');

$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');


Answer Source

Probably you have got an error about unknown index 'status' in $_GET array. Try to replace this part of your code

$check = $_GET['status'];

with this

$check = isset($_GET['status']) ? $_GET['status'] : 0;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download