How to make php comparison

This is really weird! Whenever I do this in my coding, it doesn’t make any comparison…

if ($row['subscriptionplan'] === 'None' && $subscriptionplan === 'Level 1' && $pricing_level1 =='') {
     			header("Location: update.php?upgrade=level1empty");
     			exit();

In my form page, I have the following code:

<form action="upgrade.php" method ="POST">
  <br></br>
  <select name="subscriptionplan">
    <option values="">Choose a plan</option>
    <option values="None">None</option>
    <option values="Level 1">Level 1</option>
    <option values="Level 2">Level 2</option>
    <option values="Level 3">Level 3</option>
  </select>
  <br></br>
  <select name="pricing_level1">
    <option values="">Choose a price plan for Level 1</option>
    <option values="None">None</option>
    <option values="Monthly">Monthly:$100</option>
    <option values="Yearly">Yearly:$800</option>
    </select>
  <br></br>
  <select name="pricing_level2">
    <option values="">Choose a price plan for Level 2</option>
    <option values="None">None</option>
    <option values="Monthly">Monthly:$150</option>
    <option values="Yearly">Yearly:$1300</option>
    </select>
    <br></br>
    <select name="pricing_level3">
    <option values="">Choose a price plan for Level 3</option>
    <option values="None">None</option>
    <option values="Monthly">Monthly:$200</option>
    <option values="Yearly">Yearly:$1800</option>
    </select>
    <br></br>
  <button type="submit" name="submit">Upgrade Plan</button>
 <button type="submit" name="e-mail">Email invoice</button>
</form>

But the strange thing is that if I do the following, then it does work!

if ($row['subscriptionplan'] === 'None' && $subscriptionplan === 'Level 1' && $pricing_level1 !== 'Monthly' || $pricing_level1 !== 'Yearly') {
     			header("Location: update.php?upgrade=level1empty");
     			exit();

Never mind… I think I understand the logic…

Off Topic

<br></br> is invalid HTML. The correct way to write the tag is simply <br>. However, your usage of it to add spacing is incorrect. Use CSS margins or padding for that purpose.

For more information, see:

1 Like

Another note about html usage.

Why are these options? You should use <label> elements to label your form inputs.

1 Like

I’d never realised it would work properly using values rather than value.

1 Like

Thanks for spotting that mistakes! I have to be careful not to make more typos in the future!

As explained here:

Permission tables relationships questions - #22 by TechnoBear

Remember this, @piano0011?

It is really frustrating for those trying to help to see the same problems in your code over and over again.

3 Likes

Thanks… I will try not to be forgetful next time! With regard to the select option… Can I do something like this…


 <select name="pricing_level1">
          <option value="">Choose a price plan for Level 1</option>
          <option value="None">None</option>
          <option value="100">Monthly:$100</option>
          <option value="800">Yearly:$800</option>
          </select>

That should insert the numbers into my sql table with integers shouldn’t it? Then, I can do something like this in my other page…

if ($subscriptionplan === 'Level 3' && $pricing_level1 == 200) {
                                                              
                                                              $subscriptionplan = 'Level 3';
                                                               $subscriptionplan2 = null;
                                                               $subscriptionplan3 = null;
                                                               $subscriptionplandate = null;
                                                               $subscriptionplandate2 = null;
                                                               $subscriptionplandate3 = null;
                                                               $pricing_level1 = null;
                                                               $pricing_level2 = null;
                                                               $pricing_level3 = 200;
                                                               $paid = 0;
                                                               $paid2 = null;
                                                               $paid3 = null;
                                                               $expirydate = null;
                                                               $expirydate2 = null;
                                                               $expirydate3 = null;
                                                               $paidbydate = null;
                                                               $paidbydate2 = null;
                                                               $paidbydate3 = null;
                                                               $emailreminder = 0;
                                                               $emailreminder2 = null;
                                                               $emailreminder3 = null;
                                                               $overdue = 0;
                                                               $overdue2 = null;
                                                               $overdue3 = null;
                                                               $token = 'qqewreqreqwsdfdfdafcbvcQERFGHFGHGFHRETERTDF!@#$%^^()';
                                                               $token = str_shuffle($token);
                                                               $token = substr($token, 0, 10);
                                                               $token2 = null;
                                                               $token3 = null;
                                                               $activate = 0;
                                                               $activate2 = null;
                                                               $activate3 = null;
                                                               $level1promo_activate = null;
                                                               $level2promo_activate = null;
                                                               $level3promo_activate = null;

(emphasis mine)

Do you see something wrong here?

1 Like

Thanks. . Just spotted another mismatched but will give that a go!

This is very interesting… I typed the following code in the sql phpmyadmin itself and I have the code in each if statement to state that if the user is a level 1 user, then level 2 and level 3 should be null but it came back with this error message

#1048 - Column ‘feesmonthly2’ cannot be null

… Basically, all columns with the number 1, should be filled out and those in number 2 and 3 should be null…

I typed this code in the syntax…


INSERT INTO memberships (user_uid, user_email, subscriptionplan, subscriptionplan2, subscriptionplan3, subscriptionplandate, subscriptionplandate2, subscriptionplandate3, feesmonthly, feesmonthly2, feesmonthly3, feesyearly, feesyearly2, feesyearly3, paid, paid2, paid3, expirydate, expirydate2, expirydate3, paidbydate, paidbydate2, paidbydate3, emailreminder, emailreminder2, emailreminder3, overdue, overdue2, overdue3, token, token2, token3, activate, activate2, activate3, level1promo_activate, level2promo_activate, level3promo_activate) VALUES ('piano0011', 'piano0011@hotmail.com', 'Level 1', 0, 0, '2018-06-20', null, null, 150, null, null, null, null, null, null, null, null, '2018-06-27', null, null, '2018-06-25', null, null, null, null, null, null, null, null, 'sdfdsfssdfsd', null, null, null, null, null, null, null, null)

Weird… I got it working if I added ‘null’… but I am just wondering how to do this with a variable? Should I do

$subscriptionplan2 = null;

That didn’t work…

But that’s not how you have set up your database.

Speaking of database, you DB design is seriously broken. It urgently needs normalisation. If the DB were normalised, you wouldn’t even have these problems.

4 Likes

I tried to do this in the sql query by replacing the ? with values and it does work… I don’t think it is the syntax but more of my if statement and where I place the sql and I can get that to work with my update but not on insert…

One and a half month later, still somebody is trying… my respect.

I got it working! I was using the incorrect variables… I am just wondering, with regard to setting the option to null, why won’t it allow me to activate my account? I can always update or insert into null but can’t activate? thanks!

Show us the code, and the database table information for the column you are having trouble with.

Ok @piano0011, we need to talk. Enough is enough.

That’s not the first time someone gave you that advice. In fact I’ve lost count of how many times people have told you this. Heck, somebody even gave you a much better database design on a silver platter and even gave you a several queries as examples of how to use that improved database design.

And yet you completely ignore all of this and keep going with your flawed design, which as you’re discovering now is getting harder and harder to work in, because the foundation (namely your database design) is actually working against you, instead of helping you.

Here’s the thing. All of us are here on these forums to help other people with development questions they can’t figure out for themselves. We do this for fun and because we like to solve puzzles. However, if a piece of advice given over and over again is being ignored as you are doing the fun starts to fade and as you may have noticed it’s starting to rub people the wrong way.

So, this is where we draw the line. Before you do anything, you really must fix your database first, both to preserve your own sanity as well as that of everyone who is helping you.

What that means is that

  1. I will close this thread, we will not help you any further down this road
  2. You must fix your database design, and are free to ask for any help with that over in our Databases forum. There are a lot of knowledge people there that can help you get back on track.
  3. Any thread you start that still uses the old, incorrect database schema will be made invisible on our forums, meaning no-one but you will be able to see it.

Once your database schema in order you are free to continue as you please.

With that said, thread closed.

6 Likes