Update in Postgres

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Love_Daddy
Forum Commoner
Posts: 61
Joined: Wed Jul 10, 2002 6:55 am
Location: South Africa
Contact:

Update in Postgres

Post by Love_Daddy »

Hi Guys,

I'm trying to write an update query in PHP using progres..

$sql="UPDATE users SET
name='$name',
surname='$surname',
tel_no='$telno',
cel_no=$celno
WHERE emp_no=$empno";
$results=pg_exec($connection,$sql);

But it doesn't work.
What would be a problem?

I get this msg:

Warning: PostgreSQL query failed: ERROR: parser:
parse error at or near "" in /var/www/html/shakanet/update.php on line 20
Connection to Table not established!

Of which line 20 is:
$results=pg_exec($connection,$sql);

Thanks
User avatar
Love_Daddy
Forum Commoner
Posts: 61
Joined: Wed Jul 10, 2002 6:55 am
Location: South Africa
Contact:

My situation

Post by Love_Daddy »

I'm trying to update my user table, for more than 1 field.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Have you tried echo'ing out $sql before passing it to pg_exec to make sure its the right query? Have you established the connection with pg_connect/pg_pconnect at some point in your program?
User avatar
Love_Daddy
Forum Commoner
Posts: 61
Joined: Wed Jul 10, 2002 6:55 am
Location: South Africa
Contact:

Post by Love_Daddy »

I'll try it and let you know.

Thanks
User avatar
haagen
Forum Commoner
Posts: 79
Joined: Thu Jul 11, 2002 3:57 pm
Location: Sweden, Lund

Post by haagen »

If i don't remember wrong postgres behaves a bit odd with single- and double quotes (' and "). Try to change your ' into " and see if it still complaints.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

PostGreSQL wants single quotes (')s to surround string literals in the query string, as the poster showed in code.
User avatar
haagen
Forum Commoner
Posts: 79
Joined: Thu Jul 11, 2002 3:57 pm
Location: Sweden, Lund

Post by haagen »

Then I remembered wrong. I allways mix those damn quotes. :x
Post Reply