-1

多くのフィールドを持つPHPフォームがあります。私が望むのは、これらのフィールドの内容に応じて、PostgreSQL テーブルに値を挿入するクエリにフィールドを動的に追加することです。フィールド (date、int など) が空の場合、値が挿入されるのを待っているため、テーブルに INSERT しようとすると「構文エラー」が発生するため、クエリに入れたくありません。助けてください!

編集

INSERT INTO hcd_customermeters ("meterSN", "contractCode",
                "deviceManufacturer", "deviceType",
                "firstInstallationDate", "diameter",
                "pipeID", "operatorCreator", "warehouseDeliveryDate",
                "recordCreation", "SRID") 
            VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)' 
4

1 に答える 1

3

あなたのmysqlクエリでは、変数名を定義して間違った名前を変更してください:

PHP 変数の規則:

1) variable starts with the $ sign, followed by the name of the variable
2) variable name must start with a letter or the underscore character
3) **variable name cannot start with a number**
4) variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
Variable names are case sensitive ($y and $Y are two different variables)



$sql_insert = 'INSERT INTO hcd_customermeters ("meterSN", "contractCode", "deviceManufacturer", "deviceType", "firstInstallationDate", "diameter", "pipeID", "operatorCreator", "warehouseDeliveryDate", "recordCreation", "SRID") 
            VALUES ("'.$variableName."', "'.$variableName."', "'.$variableName."',"'.$variableName."', "'.$variableName."', "'.$variableName."', "'.$variableName."', "'.$variableName."', "'.$variableName."', "'.$variableName."',"'.$variableName."')';


mysql_query($sql_insert);

問題がある場合は、ご連絡ください。

于 2013-10-23T12:27:37.333 に答える