tags:

views:

62

answers:

2

Here is my code:

if (isset($_POST['addmonths'])){
    if (!empty($_POST['months'])){
        if (is_numeric($_POST['months'])){
            $monthtoadd = $_POST['months'];
            if ($monthstoadd == 0){
                mysql_query("UPDATE users SET months='lifetime' WHERE username='$lookupuser'");
                echo "Successfully set " . $lookupuser . " to lifetime" . $monthstoadd;
            }elseif ($monthstoadd > 0){
                $monthstoadd = $monthstoadd*2592000;
                mysql_query("UPDATE users SET months=months+'$monthstoadd' WHERE username='$lookupuser'");
                echo "Successfully added " . $monthstoadd . " months to " . $lookupuser . "'s paid time.";
            }else{
                echo "Error.";
            }
        }else{
            echo "Months need to be numeric. If you're trying to set lifetime, use 0.";
        }
    }else{
        echo "You didn't enter anything.";
    }
}

No matter what number I enter, it always seems to set it to lifetime, and then it doesn't echo the $monthstoadd after it, which is just there to help me see why it's not working. I can't figure this out for the life of me. If I don't enter anything, it echos You didn't enter anything. like its supposed to, and if its not a number, it echos Months need to be numeric. If you're trying to set lifetime, use 0. like its supposed to.

Anyone have any ideas?

+6  A: 

Line 4:

$monthtoadd = $_POST['months'];

Should be $monthstoadd (note the missing s)

TomWilsonFL
Ugh. Its always the small shit I overlook. Thanks, buddy
Rob
that's why i love compiled languages, compiler will never let this go
Andrey
@Andrey: Interpreted languages can also be explicit about variable declaration; they just tend not to be.
Eric Mickelsen
This is why it's extremely helpful to develop with display_errors on and have the error_reporting level set high enough to report undefined variables.
Chris Henry
Or with a decent IDE.
Felix Kling
+6  A: 
$monthtoadd = $_POST['months'];

should be

$monthstoadd = $_POST['months'];
Eric Mickelsen
that's why i love compiled languages, compiler will never let this go
Andrey