Jump to content

edit profile code


Doug

Recommended Posts

I am trying to buld an area for users to login and edit thier profiles. it all works except for the area in which they can add a picture if they wish.

 

I get the follwing error messages:

 

Notice: Undefined variable: query in C:\Program Files (x86)\EasyPHP5.2.10\www\OneSevenoaks\editprofile3.php on line 205

 

Warning: mysqli_query() [function.mysqli-query]: Empty query in C:\Program Files (x86)\EasyPHP5.2.10\www\OneSevenoaks\editprofile3.php on line 205

 

Notice: Undefined variable: query in C:\Program Files (x86)\EasyPHP5.2.10\www\OneSevenoaks\editprofile3.php on line 205

 

Query

Failed with error:

On line: 205

 

This problem occurred as I solved another problem with age so I think the two are connected but I can't see the problem.

 

Any help most appreciated

 

Relevant code:


// Update the profile data in the database
    
if (!$error) {
      if (!empty($first_name) && !empty($last_name) && !empty($username) && !empty($gender) && !empty($email)) {
        // Only set the picture column if there is a new picture
// Only set the password in there is a new one
        if (!empty($new_picture)) {
if (!empty($new_password1)) {
if (empty($age)) {
          $query = "UPDATE registration SET first_name = '$first_name', last_name = '$last_name', username = '$username', gender = '$gender', " .
            " email = '$email', age = '$age',  password = '$new_password1', picture = '$new_picture' WHERE user_id = '" . $_SESSION['user_id'] .
"'";
        }
}}
       
        else {
          
$query = "UPDATE registration SET first_name = '$first_name', last_name = '$last_name', age = '$age', username = '$username', gender = '$gender', " .
            " email = '$email', lookingfor = '$lookingfor', haircolor = '$haircolor', " .
    " height = '$height', education = '$education', drink = '$drink', children = '$children', ethnicity = '$ethnicity', " .
    " smoker = '$smoker', interests = '$interests', aboutme = '$aboutme', password = '$new_password1', picture = 'new_picture' WHERE user_id = '" . 

$_SESSION['user_id'] . "'";
        }
        mysqli_query($dbc, $query) or die("<br>Query $query<br>Failed with error: " . mysqli_error($dbc) . '<br>On line: ' . __LINE__); 

        

Link to comment
https://forums.phpfreaks.com/topic/239917-edit-profile-code/
Share on other sites

You should properly indent your code blocks - especially when you have nested if/else statements. If so, you may have seen the error.

 

You have a top-level if/else statement where you are checking if several fields are empty. If not, you will have a defined query in the ELSE condition. however, if the first IF condition is true, you have two child-level IF statement. And, only if those two child-level IF statemetns are true are you defining a query. No query is defined if the first IF condition is true and one of the child IF statements are false. You also seem to be missing a couple of {}.

 

Here is your code with everything indented based upont he logic - I added a couple of ELSE conditions to show where the error is likely occuring

if (!$error)
{
    if (!empty($first_name) && !empty($last_name) && !empty($username) && !empty($gender) && !empty($email))
    {
        // Only set the picture column if there is a new picture
       // Only set the password in there is a new one
        if (!empty($new_picture))
        {
           if (!empty($new_password1))
            {
               if (empty($age))
                {
                    $query = "UPDATE registration
                              SET first_name = '$first_name', last_name = '$last_name', username = '$username',
                                  gender = '$gender', email = '$email', age = '$age',  password = '$new_password1',
                                  picture = '$new_picture' WHERE user_id = '" . $_SESSION['user_id'] ."'";
                }
                else
                {
                    //No query defined
                }
            }
            else
            {
                //No query defined
            }
        }
        else
        {
            $query = "UPDATE registration
                      SET first_name = '$first_name', last_name = '$last_name', age = '$age', username = '$username',
                          gender = '$gender', email = '$email', lookingfor = '$lookingfor', haircolor = '$haircolor',
                          height = '$height', education = '$education', drink = '$drink', children = '$children',
                          ethnicity = '$ethnicity', smoker = '$smoker', interests = '$interests', aboutme = '$aboutme',
                          password = '$new_password1', picture = 'new_picture' WHERE user_id = '" . $_SESSION['user_id'] . "'";
        }

    }
}

Link to comment
https://forums.phpfreaks.com/topic/239917-edit-profile-code/#findComment-1232400
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.