0

After getting the user-info from my sql database I would like to check if some of the fields are empty and continue the script based on that. A simplified piece of code would look like this:

$userData = mysql_query("SELECT * FROM user WHERE user='".$user."' LIMIT 1");

if(mysql_num_rows($data) == 1){

    $u_info = mysql_fetch_assoc($data);

    if(empty($u_info['u_mobile'])){
        echo 2;
        exit();
    } else {
        echo 1;
        exit();
    }

} else {

    echo 3;
    exit();
}

The problem is the empty statement checking the recieved field. I've tried using empty(), isset(), not_null() and array_key_exists() with no luck and can't get around to what I'm doing wrong. I also tried if($u_info['u_mobile']) == '' || $u_info['u_mobile']) == NULL) but that doesnæt work either.

Why is this, or how can I go about getting this information?

I need to collect the user-information and send them to fill out the information I don't have...

1
  • can you add the var_dump($u_info) to see if you are getting the correct row? "does not work" means the field is blank and you are not being displayed the correct text? Commented Mar 6, 2014 at 14:59

2 Answers 2

2

You're setting the query result to $userData but then you're using mysql_fetch_assoc($data); -- doh. You need to pass the variable that you set the query result to:

$u_info = mysql_fetch_assoc($userData);

It's OK, it is still 10AM EST so this can happen in the morning =) I suggest that you turn on PHP error reporting. PHP would have alerted you that the array values were trying to access do not exist, saving you a lot of wasted frustration.

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

1 Comment

Well, that's embarrassing. Thanks :)
0
$userData = mysql_query("SELECT * FROM user WHERE user='".$user."' LIMIT 1");

if(mysql_num_rows($userData ) == 1){

    $u_info = mysql_fetch_assoc($userData );

    if(empty($u_info['u_mobile'])){
        echo 2;
        exit();
    } else {
        echo 1;
        exit();
    }

} else {

    echo 3;
    exit();
}

Please Run code..I think it will be compile better it was minor mistake

Comments

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.