Jump to content

[SOLVED] PHP + SQL


rhyspaterson

Recommended Posts

Hey guys,

 

Receiving the following syntax error:

 

Warning: pg_exec() [function.pg-exec]: Query failed: ERROR: syntax error at or near "user" LINE 1: UPDATE user SET name = 'Joe Blogs', password = 'ck2007' ... ^ in /var/www/menu/client/form/process.php on line 435

 

The command being used is:

 

$result = pg_exec($dbconn, "UPDATE user SET name = '$username', password = '$userPassword' WHERE id = '$userID'");

 

All the variables are fine, just not sure what's wrong with the statement.. any suggestions?

 

Ta!

Link to comment
https://forums.phpfreaks.com/topic/59037-solved-php-sql/
Share on other sites

User is a reserved word in PostgreSQL. Having only ever used mysql, i cant guarantee it, but i would guess the quickfix is to use backticks (`) around your field names:

 

$result = pg_exec($dbconn, "UPDATE `user` SET `name` = '$username', `password` = '$userPassword' WHERE id = '$userID'");

 

The proper solution is to not use reserved words as table or column names.

Link to comment
https://forums.phpfreaks.com/topic/59037-solved-php-sql/#findComment-293059
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.