Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>see <a href="http://www.postgresql.org/docs/8.1/static/sql-update.html" rel="nofollow noreferrer">http://www.postgresql.org/docs/8.1/static/sql-update.html</a></p> <pre><code>UPDATE users SET aboutSelf='...', hobbies='...', music='...', tv='...', sports='...' WHERE email='something' </code></pre> <p>edit: a self-contained example using <a href="http://docs.php.net/pg_prepare" rel="nofollow noreferrer">pg_prepare()</a>:</p> <pre><code>$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"; } </code></pre> <p>prints</p> <pre><code>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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload