Forum Moderators: coopster

Message Too Old, No Replies

php/postgresql insert problem

         

denzity

7:29 am on May 14, 2004 (gmt 0)

10+ Year Member



Can someone see what it is that I'm missing here usually this error message means I've got the single or double quote mixed up. But have tried swapping around with out any success.

$NPquery= 'INSERT into "tbl" values ('.$_POST['first'].','.$_POST['last'].')';
$result=pg_query($dbh, $NPquery) ;
print_r($NPquery);

This returns

Warning: pg_query() query failed: ERROR: Attribute "test" not found in /var/www/html/site1/NP2.php on line 51
INSERT into "tbl" values (test,test2)

The 2 values I am trying to insert are coming through 'test and test2' so why wont the insert work?
DBMS is Postgresql

Any help appreciated

Bob

dcrombie

9:42 am on May 14, 2004 (gmt 0)



Your query is coming out as:

INSERT into "tbl" values (test,test2)

when it should be:

INSERT INTO tbl (var1, var2) VALUES ('test', 'test2');

denzity

11:33 am on May 14, 2004 (gmt 0)

10+ Year Member



Hmm are you sure about that? there are only 2 columns to the table. Running the query in terminal it accepts

Insert into "tbl" values( 'test1', 'test2)

I will try it though :) tomorrow, its late now.

Thanks for the reply

Bob

dcrombie

12:10 pm on May 14, 2004 (gmt 0)



The '(var1, var2)' are optional (but highly recommended) - your main problem is with the single quotes around the values.

denzity

11:19 pm on May 14, 2004 (gmt 0)

10+ Year Member



this is the solution, needed to escape the double quotes around tbl and put {} around variable.

$NPquery= "INSERT into \"tbl\" values ('{$_POST['first']}','{$_POST['last']}')";
$result=pg_query($dbh, $NPquery) ;
print_r($NPquery);

thanks for the replies.

D