I am trying to allow the user to upgrade his or her subscription plan and I thought the logic would be to check to see if each of my table in my database is empty or not. I only know how to match my subscriptionplan, subscriptionplan2 and subscriptionplan3 based on my subscriptionplan1, subscriptionplan2 and subscriptionplan 3 table… I am not sure if I am confusing you guys but I will include some pictures of my websites to show you what I am trying to do here first, then provide my code:
This is the page where the user can upgrade his or her details:
and this is my database, where the user can upgrade his or her plan:
This is my code to upgrade the user
<?php
session_start();
if(!isset($_SESSION['u_uid'])) {
header("Location: ../index.php?subscription=notlogin");
exit();
} else {
include_once 'dbh.php';
include_once '../index.php';
$expired =0;
$fees =0;
$overduefees = 0;
$subscriptionplan = mysqli_real_escape_string($conn, $_POST['subscriptionplan']);
$subscriptionplan2 = mysqli_real_escape_string($conn, $_POST['subscriptionplan2']);
$subscriptionplan3 = mysqli_real_escape_string($conn, $_POST['subscriptionplan3']);
// Check to see if lesson plan has been previously selected
$sql = "SELECT * FROM user_lessonsubscription WHERE user_uid='".$_SESSION['u_uid']."'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if($resultCheck > 0) {
while($row = mysqli_fetch_assoc($result)) {
if($row['subscriptionplan'] != '' || $row['subscriptionplan2'] != '' || $row['subscriptionplan3'] != '') {
header("Location: update.php?update=plannotempty");
exit ();
} else {
if ($row['subscriptionplan'] == '') {
$sql = "UPDATE user_lessonsubscription
SET subscriptionplan = '$subscriptionplan'
WHERE user_uid ='".$_SESSION['u_uid']."'
";
mysqli_query($conn, $sql);
} else {
if ($row['subscriptionplan2'] == '') {
$sql = "UPDATE user_lessonsubscription
SET subscriptionplan2 = '$subscriptionplan2'
WHERE user_uid ='".$_SESSION['u_uid']."'
";
mysqli_query($conn, $sql);
} else {
if ($row['subscriptionplan3'] == '') {
$sql = "UPDATE user_lessonsubscription
SET subscriptionplan3 = '$subscriptionplan3'
WHERE user_uid ='".$_SESSION['u_uid']."'
";
mysqli_query($conn, $sql);
}
}
}
}
}
}
I hope I haven’t made any typos…