Riyadh Riyadh - 5 months ago 11
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:

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

if ($check == '1') {
//Do something
}
else{
//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.

Edit:

The actual code

<?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';
}
}
?>


The actual form code:

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


Here is the php for storing the data:

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

Answer

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;