1

私は何時間もコードを扱ってきましたが、どこにエラーがあるのか​​わかりません。これは問題のあるコードです

$answercreatequery = pg_query("INSERT INTO answer (answerid, questionid, adescription, afilelocation, iscorrect) VALUES( default, '".$thisquestionid."', '".$adescription1."', '".$afilelocation."', '".$iscorrect1."' ");

そしてこれは報告されたエラーです

警告:pg_query()[function.pg-query]:クエリに失敗しました:エラー:入力の最後に構文エラーがありますLINE 1:... on、iscorrect)VALUES(default、 '37'、'kyfhdkj'、'none'、 ''^/ceri/homes1/m/mtp4/public_html/mmp/Quizmaker/Clientside/questioncreatescript.phpの167行目

私が見逃している単純なものがあるかどうか疑問に思っていますか?$ iscorrect1はブール型であり、さまざまな方法で編集しようとしましたが、それでも同じ種類のエラーが発生するためだと思います。

/d回答表

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)
4

1 に答える 1

6

)クエリの最後でを忘れました:

$answercreatequery = pg_query("INSERT INTO answer (answerid, questionid, adescription, afilelocation, iscorrect) VALUES( default, '".$thisquestionid."', '".$adescription1."', '".$afilelocation."', '".$iscorrect1."' ");
........................................................................................................................................................................................................insert ) here ^

さらに、デフォルト値を使用する列を省略できます。

$answercreatequery = pg_query("INSERT INTO answer
  (questionid, adescription, afilelocation, iscorrect) VALUES
  ('".$thisquestionid."', '".$adescription1."', '".$afilelocation."', '".$iscorrect1."')");

さらに、(エスケープしたり、SQLインジェクションホールを作成したりする代わりに)実際に使用する必要があります。pg_query_params

$answercreatequery = pg_query_params('INSERT INTO answer
  (questionid, adescription, afilelocation, iscorrect) VALUES ($1, $2, $3, $4)',
  array($thisquestionid, $adescription1, $afilelocation, $iscorrect1));

そうすることで、コードがはるかに読みやすくなります。

于 2013-01-27T12:48:25.160 に答える