Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts

    Updating specific area of table in postgresql

    Ok I am trying to update a specific area of a table in postgresql

    I want it to find the user that goes along with the table

    and then update the information I have

    like in this case the email is the user name that it needs to look for.

    it needs to add in areas like $aboutSelf, $hobbies, $music, $tv, $sports

    so ya I have no idea how to do this lol ^.^ I only know how to add stuff from scratch. like create a non existing user
    Continually Learning

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    You want to add more columns to the user table and add info to those columns for one user, or just update existing columns for one specific user?

  • #3
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts
    update existing blank colums for the user

    Code:
    DROP TABLE chatterprofileinfo;
    
    CREATE TABLE chatterprofileinfo(
    	Id SERIAL,
    	email VARCHAR(255) NOT NULL PRIMARY KEY,
    	aboutSelf VARCHAR(255),
    	hobbies VARCHAR(255),
    	music VARCHAR(255),
    	tv VARCHAR(255),
    	sports VARCHAR(255),
    	lastLogin DATE
    );
    that is the SQL email is already filled in and is the username so i need to somehow find specific email and put in stuff according to the email

    currently trying to use

    $query = pg_query("UPDATE chatterprofileinfo SET aboutSelf='$aboutSelf', hobbies='$hobbies', music='$music', tv='$tv', sports='$sports', lastLogin='now()' WHERE email='$username'");

    and i dont think its working
    Last edited by MrEnder; 04-02-2010 at 09:06 PM.
    Continually Learning

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    UPDATE chatterprofileinfo SET hobbies='[new hobby]', sports='[new sports]' WHERE email='email@example.org';
    Obviously, replace the bracketed portions with the info you're actually entering.


    Edit: You edited whilst I was typing. Try this and see if it prints an error.

    Code:
    $query = pg_query("UPDATE chatterprofileinfo SET aboutSelf='$aboutSelf', hobbies='$hobbies', music='$music', tv='$tv', sports='$sports', lastLogin='now()' WHERE email='$username'") or exit(pg_last_error());
    Last edited by MattF; 04-02-2010 at 09:12 PM.

  • #5
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts
    that works with the exception that its being put into an area with no e-mail and the e-mail is disappearing 0.0

    (sorry for the late reply I fell asleep at the PC lol)
    Continually Learning

  • #6
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by MrEnder View Post
    that works with the exception that its being put into an area with no e-mail and the e-mail is disappearing 0.0
    That means, exactly?

  • #7
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts
    ok when i print out the database there is nothing in the email slot thats what i mean. so its posting stuff when there isnt even that area =[
    Continually Learning


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •