Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 695353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:57:02+00:00 2026-05-14T02:57:02+00:00

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

  • 0

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

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

The PHP im currently using

<?php

$error=false;

$aboutSelfError="";
$hobbiesError="";
$musicError="";
$tvError="";
$sportsError="";

if($_SERVER["REQUEST_METHOD"] == "GET") {

    $aboutSelf="";
    $hobbies="";
    $music="";
    $tv="";
    $sports="";
    $error=false;

}
else if($_SERVER["REQUEST_METHOD"] == "POST") {

    $error=false;

    $aboutSelf=trim($_POST["aboutSelfTA"]);
    $hobbies=trim($_POST["hobbiesTA"]);
    $music=trim($_POST["musicTA"]);
    $tv=trim($_POST["tvTA"]);
    $sports=trim($_POST["sportsTA"]);

    if(strlen($aboutSelf)>255) {

        $aboutSelfError="Maximum of 255 characters please shorten";

        $error=true;

    }

    if(strlen($hobbies)>255) {

        $hobbiesError="Maximum of 255 characters please shorten";

        $error=true;

    }

    if(strlen($music)>255) {

        $musicError="Maximum of 255 characters please shorten";

        $error=true;

    }

    if(strlen($tv)>255) {

        $tvError="Maximum of 255 characters please shorten";

        $error=true;

    }

    if(strlen($sports)>255) {

        $sportsError="Maximum of 255 characters please shorten";

        $error=true;

    }

}

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:57:02+00:00Added an answer on May 14, 2026 at 2:57 am

    see http://www.postgresql.org/docs/8.1/static/sql-update.html

    UPDATE
      users
    SET
      aboutSelf='...',
      hobbies='...',
      music='...',
      tv='...',
      sports='...'
    WHERE
      email='something'
    

    edit: a self-contained example using pg_prepare():

    $pg = pg_connect("dbname=test user=localonly password=localonly");
    if ( !$pg ) {
      die('connect failed ');
    }
    
    // create a temporary/test table
    pg_query($pg, '
      CREATE TEMPORARY TABLE tmpchatter (
        id SERIAL, 
        email varchar,
        aboutSelf varchar,
        hobbies varchar,
        UNIQUE (email)
      )
    ');
    
    // fill in some test data
    pg_query("INSERT INTO tmpchatter(email, aboutSelf, hobbies) VALUES ('emailA','aboutA','hobbiesA')") or die(pq_last_error($pg));
    pg_query("INSERT INTO tmpchatter(email, aboutSelf, hobbies) VALUES ('emailB','aboutB','hobbiesB')") or die(pq_last_error($pg));
    pg_query("INSERT INTO tmpchatter(email, aboutSelf, hobbies) VALUES ('emailC','aboutC','hobbiesC')") or die(pq_last_error($pg));
    
    // let's see what we've got so far
    $result = pg_query('SELECT email,aboutSelf,hobbies FROM tmpchatter') or die(pq_last_error($pg));
    echo "query result #1:\n";
    while ( false!==($row=pg_fetch_row($result)) ) {
      echo join(', ', $row), "\n";
    }
    
    // now let's update a specific record
    // the "interesting" part
    
    // first the parameters we want to use
    $email = 'emailB';
    $about = 'about me....';
    $hobbies = 'breathing, eating';
    
    // prepare the statement. Put placeholders where you want to "insert" parameters
    pg_prepare($pg, '', '
      UPDATE
        tmpchatter
      SET
        aboutSelf = $1,
        hobbies = $2
      WHERE
        email = $3
    ') or die(pg_last_error());
    
    // execute the statement + provide the parameters
    // With prepared statements you don't have to worry about escaping the values to avoid sql injections
    pg_execute($pg, '', array($about, $hobbies, $email)) or die(pg_last_error());
    
    // let's check the result
    $result = pg_query('SELECT email,aboutSelf,hobbies FROM tmpchatter') or die(pq_last_error($pg));
    echo "query result #2:\n";
    while ( false!==($row=pg_fetch_row($result)) ) {
      echo join(', ', $row), "\n";
    }
    

    prints

    query result #1:
    emailA, selfA, hobbiesA
    emailB, selfB, hobbiesB
    emailC, selfC, hobbiesC
    
    query result #2:
    emailA, selfA, hobbiesA
    emailC, selfC, hobbiesC
    emailB, about me...., breathing, eating
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to update only some information for a user. Specifically, I don't want
I have an Activity in which user can update a specific information clicking in
I am trying to update a specific row that uses auto_increment as a primary
I'm trying to run an update query that updates one table based on rows
I am trying to update specific rows in a master table from data in
I am trying to update a column in my table which was last inserted.
I am trying to update a field in a table with data from another
I am trying to update the Roles a specific group has in my application.
I'm trying to update a field in one table, from the sum of another
I am trying to update a #temp table from a linked server using a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.