Jump to content

PHP profile


mattheww

Recommended Posts

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!  :confused: 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'");}
?>

 

Link to comment
Share on other sites

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'");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.