Pat
Pat

Reputation: 41

postgresql 9. update not working

I am using PostgreSQL 9. When trying to do this update, row table does not get updated.

$cmd = "UPDATE table1 SET field1 = '$value1'  WHERE key_field = '$key_value'; ";

table1 has privileges for PUBLIC to INSERT and UPDATE.

When using pgAdmin III SQL console it does perfectly the job.

Upvotes: 2

Views: 2198

Answers (2)

Milen A. Radev
Milen A. Radev

Reputation: 62573

  1. Don't use variable parsing (or string concatenation) to build SQL queries;

  2. What does "using PgAdminIII sql console it does perfectly the job" mean? You have pasted the same query in pgAdmin3 and it worked? I very much doubt pgAdmin3 understands PHP and does PHP-style variable parsing as a consequence. If it was not exactly the same query (most probably it was one with the PHP variables replaced with literals) what was the query you tested in pgAdmin3?

  3. Most probably the reason the update is ineffective is that there are no rows that satisfy your WHERE clause.

Upvotes: 2

gmhk
gmhk

Reputation: 15940

$cmd = "UPDATE table1 SET field1 = '$value1' WHERE key_field = '$key_value'";

Now try there was an extra ;

Upvotes: 0

Related Questions