1

I can't find anything wrong with this... This should work right?

function ConfirmedNumber()
{
$rs = mysql_query("CALL ConfirmedNumber('" , $_SESSION['UserID'] . "',@Active)");
    while ($row = mysql_fetch_assoc($rs))
    {
        if ($row['Active'] = 1)
        {
        return true;
        }
    }
return false;
}

Assuming the Stored procedure returns a single row with the value '1' in it then I can call the function like this right?

if (ConfirmedNumber())
{
//do some stuff.
}
3
  • 1
    $row['Active'] = 1 should be $row['Active'] === 1 Commented Aug 29, 2011 at 1:46
  • yep, $row['Active'] = 1 will always be true, since he can assign 1 to $row['Active'], therefore return true. Commented Aug 29, 2011 at 1:47
  • @adlawson: $row['Active'] === 1 --- will always be false Commented Aug 29, 2011 at 1:54

3 Answers 3

2

To expand on my comment:

if ($row['Active'] = 1) should be if ($row['Active'] == 1) to work correctly.

If you want to avoid accidentally doing this in future, you could write your if statements like this:

if (1 == $row['Active'])

This way, you can't accidentally use = as PHP will throw a Fatal Error. You can read more about Comparison Operators at PHP.net


Comment below with the full answer:

The call to the stored proc... line $rs = mysql_query("CALL ConfirmedNumber('" . $_SESSION['UserID'] . "',@Active)"); had a comma instead of the period in the initial post.

Sign up to request clarification or add additional context in comments.

6 Comments

What type do all the fields retrieved from mysql have?
@adlawson This still isn't working for some reason. Could it be that my function call is bad?
@kulingar If you have a row in which 'Active' == 1, then everything looks ok, but without seeing a data dump it's difficult to tell why. The function call is perfectly fine.
@adlawson I run the stored procedure and come up with one result, column exactly titled "Active" and 1 in the cell (I personally hate how MySQL changes boolean to a tinyint with a length of 1). I'm exceptionally new to MySQL and PHP. I'm going to look into this data dump to see what's up. Will post with response. Thanks.
|
1

you forgot your operator in your IF statement. Change it to this:

if ($row['Active'] == 1)

or even shorter

if ($row['Active'])

1 Comment

The equivalence operator is making no difference. Is my call to the function correct? Or are you referring to the if statement that calls the funciton? hrm.
0

it can be something like this

    function ConfirmedNumber($id)
    {
    $rs = mysql_query("CALL ConfirmedNumber('" . $id . "',@Active)");
        while ($row = mysql_fetch_assoc($rs))
        {
            if ($row['Active'] == 1)
            {
            return true;
            }
        }
    return false;
    }
ConfirmedNumber($_SESSION['UserID']);

2 Comments

No need to waste the bandwidth passing the session variable to the function. Might as well call it inside the function. Plus this isn't what my problem was. :(
the condition must be like that $row['Active'] == 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.