I have been working with code for hours and just cannot see where I have an error. This is the offending code
$answercreatequery = pg_query("INSERT INTO answer (answerid, questionid, adescription, afilelocation, iscorrect) VALUES( default, '".$thisquestionid."', '".$adescription1."', '".$afilelocation."', '".$iscorrect1."' ");
And this is the error reported
Warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax
error at end of input LINE 1: …on, iscorrect) VALUES( default, ’37’,
‘kyfhdkj’, ‘none’, ” ^ in
/ceri/homes1/m/mtp4/public_html/mmp/Quizmaker/Clientside/questioncreatescript.php
on line 167
I am wondering if there is something simple I am missing? I have suspected it was because $iscorrect1 is type boolean and I have tried editing it in many ways but still I get the same kind of error.
/d answer table
Column | Type | Modifiers
---------------+------------------------+-----------------------------------------------------------
answerid | integer | not null default nextval('answer_answerid_seq'::regclass)
questionid | integer | not null
adescription | character varying(200) | not null
afilelocation | character varying(200) | not null
iscorrect | boolean | not null
Indexes:
"answer_pkey" PRIMARY KEY, btree (answerid)
Foreign-key constraints:
"answer_questionid_fkey" FOREIGN KEY (questionid) REFERENCES question(questionid)
You forgot a
)at the end of your query:Besides that, you can simply omit the column where you want the default value to be used:
Additionally, you should really use
pg_query_params(instead of escaping or having a sql injection hole):Doing so also makes your code much more readable.