<?php 
include ('database.php');
session_start();

if(isset($_POST['submit']));
{
    
    $name = mysqli_real_escape_string($connection, $_POST['name']);
    $id = mysqli_real_escape_string($connection, $_POST['id']);
	$phone = mysqli_real_escape_string($connection, $_POST['phone']);
	$paddress = mysqli_real_escape_string($connection, $_POST['paddress']);
    $cardtype = mysqli_real_escape_string($connection, $_POST['cardtype']);
    $notification = "Card Requested";
	$icon= "card-outline";
	$icolor= "bg-primary";
	$status="Pending Approval";
	$scolor="text-warning";
	$amount= $_POST['cardtype'];
	$acolor= "bg-primary";
	
   $verify_query = "SELECT identification, id FROM users WHERE id='$id' LIMIT 1";
   $verify_query_run = mysqli_query($connection, $verify_query);

   if(mysqli_num_rows($verify_query_run) > 0)
   {
      $row = mysqli_fetch_array($verify_query_run);
      if($row['identification'] == "1")
      {
  
     $query = "INSERT INTO crequest (name, id, phone, paddress, ctype, status) VALUES ('$name', '$id', '$phone', '$paddress', '$cardtype', '0')";
     $query_run = mysqli_query($connection, $query);
    if($query_run)
    {
	$notification_query = "INSERT INTO `notifications` (id, notification, icon, icolor, status, scolor, amount, acolor) VALUES ('$id', '$notification', '$icon', '$icolor', '$status', '$scolor', '$amount', '$acolor')";
     $notification_query_run = mysqli_query($connection, $notification_query);	
	 $_SESSION['id'] = $id;
	  
	 header("location:../payment.php"); 
 }
 else
 {
	  $_SESSION['status'] = "<h5 style='padding:8px; background: #fe8b8e; border-radius: 10px; color: #fff; text-align: center;'>Failed Upgrade account</h5>";
       
	header("location: ../card.php");  
 }
}else{
	 $_SESSION['status'] = "<h5 style='padding:8px; background: #fe8b8e; border-radius: 10px; color: #fff; text-align: center;'>Failed Upgrade account</h5>";
       
	header("location: ../card.php");  
}
   }
   else{
	 $_SESSION['status'] = "<h5 style='padding:8px; background: #fe8b8e; border-radius: 10px; color: #fff; text-align: center;'>Failed Upgrade account</h5>";
       
	header("location: ../card.php");  
}
}
?>