mattheww Posted December 11, 2009 Share Posted December 11, 2009 I'm trying to make a user profile system, but I'm not sure how to make it so they can edit their information... I have given the section of code which is supposed to update the table which stores the information, but it doesn't work, and I'm not sure where I'm going wrong! Is there a better/easier way to do this? <?php if ($_POST['submit']) { $fname = strip_tags($_POST['fname']); $lname = strip_tags($_POST['lname']); $location = strip_tags($_POST['location']); $bday = strip_tags($_POST['dob']); $about = strip_tags($_POST['about']); $favgames = strip_tags($_POST['favgames']); include('connect.php'); $queryget = mysql_query("SELECT * FROM users WHERE username='$user'") or die ("Failed to find user details"); $row = mysql_fetch_assoc($queryget); $querychange = mysql_query ("UPDATE users SET fname='$fname', lname='$lname', SET location='$location', SET dob='$bday', SET about='$about', SET favgames='$favgames' WHERE username='$user'");} ?> Quote Link to comment https://forums.phpfreaks.com/topic/184812-php-profile/ Share on other sites More sharing options...
ignace Posted December 11, 2009 Share Posted December 11, 2009 Is there a better/easier way to do this? Never ask if their is a better or easier way of doing something because their always most likely is (this is especially true for people balancing between novice and intermediate) It could be something like: // this example however misses proper validation plus testing $user = $userTable->find($request->getParameter('id')); $form = new UserForm(); $form->populate($user); if ($request->isPost() && $form->isValid($request->getPost())) { $user->updateUserData($form->getValues()); // validate, filter & assign data $user->save(); // update row } $view->form = $form; You may also notice that this example has 2 states: retrieving the data and storing the data you could separate this process so you would only query the db 2 times instead of 3 times like it is now. Now back to your original question, the solution lies within your UPDATE satement which is incorrect and should have been: $querychange = mysql_query ("UPDATE users SET fname='$fname', lname='$lname', location='$location', dob='$bday', about='$about', favgames='$favgames' WHERE username='$user'"); Quote Link to comment https://forums.phpfreaks.com/topic/184812-php-profile/#findComment-975670 Share on other sites More sharing options...
mattheww Posted December 11, 2009 Author Share Posted December 11, 2009 ahhhh, I didn't see all those "sets" in there when I looked! Thankyou Quote Link to comment https://forums.phpfreaks.com/topic/184812-php-profile/#findComment-975673 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.