Can't update user's lesson plan in php


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


if(!isset($_SESSION['u_uid'])) {
	header("Location: ../index.php?subscription=notlogin");
} 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....


Your database table design is pretty fubar. I would recommend you look into database designing and normalization. Redesign your db and proceed from there.

Also I think you haven't understood how else-if works. The first if/elseif clause that evaluates TRUE will get executed and the rest won't. So with your code If first plan is empty string the second and third plan will not get updated to db at all even if they had values in them.

I would probably break that table to two tables. Something like below..


user_id (refers to user table id column)

closed #3

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.