Doug Posted June 20, 2011 Share Posted June 20, 2011 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__); Quote Link to comment https://forums.phpfreaks.com/topic/239917-edit-profile-code/ Share on other sites More sharing options...
TeNDoLLA Posted June 20, 2011 Share Posted June 20, 2011 I think you shud use some echoes for $query and some inside the if's to see where your program goes, what your variables holds and if the sql queries are correct. Your also missing exclamation mark before the check of age, not sure if that is on purpose. Quote Link to comment https://forums.phpfreaks.com/topic/239917-edit-profile-code/#findComment-1232391 Share on other sites More sharing options...
Doug Posted June 20, 2011 Author Share Posted June 20, 2011 it seems it was the exclamation mark. I had left it out on purpose but adding it seems to have worked! I'm still learning! thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/239917-edit-profile-code/#findComment-1232394 Share on other sites More sharing options...
Psycho Posted June 20, 2011 Share Posted June 20, 2011 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'] . "'"; } } } Quote Link to comment https://forums.phpfreaks.com/topic/239917-edit-profile-code/#findComment-1232400 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.