My IF statement is changing variables in PHP

Posted by user1902509 on Stack Overflow See other posts from Stack Overflow or by user1902509
Published on 2012-12-14T16:54:33Z Indexed on 2012/12/14 17:03 UTC
Read the original article Hit count: 180

Filed under:
|

I am fairly new to the whole programming thing, so forgive me if this is a stupid question. It seems odd that I haven't run into it before.

I am trying to make an order form for a cake. You fill out the form, submit it, and it will then display the order in a new window, where you then hit "submit," and upload it to the Database. I have a series of If Statements to check for errors in the form before submitting it. Here is a simplified version of the code. Writing means any writing you want on the cake, Name is your name, and cake is what type of cake you want (the default is "None").

try {
$name = trim($params->name);
$cake = trim($params->cake);
$writing = trim($params->writing);
if (strlen($name) < 3){
    throw new Exception("Please enter Your name.");
    }
if ($cake = "None") {
        throw new Exception("Please select a Cake"
     }
if ($cake = "Caramel Apple Pie" or $cake = "Pumpkin Pie" or $cake = "Eggnog Pie" and strlen($writing) > 1) {
    throw new Exception("We are sorry, but you can't write on any of our specialty pies.");
    }

} catch(Exception $x) {
    $error = $x->getmessage();
    }

So what is happening is that when I go and hit submit the first time, the correct cake type comes up, but when you submit it the second time, the error comes up saying that I have "None" selected. All the other values are there and remain the same. I think the problem is that the first "IF" statement (Where it says "If($cake = "None")) is automatically changing $cake to "None" because I have tried commenting just that statement out, and it will then change the cake to be "Caramel Apple Pie," which is in the top of the next IF statement.

Anyone know why it is doing this? And how to fix it?

© Stack Overflow or respective owner

Related posts about php

Related posts about if-statement