Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 动态SQL插入_Php_Postgresql_Select_Dynamic - Fatal编程技术网

Php 动态SQL插入

Php 动态SQL插入,php,postgresql,select,dynamic,Php,Postgresql,Select,Dynamic,我有一个PHP表单,它有许多字段。我想要的是动态地向查询添加字段,根据这些字段的内容在PostgreSQL表中插入值。如果一个字段(如date、int等)为空,我不希望它出现在查询中,因为当我试图插入到表中时,它会在等待插入值时导致“语法错误”。救命啊 编辑 在mysql查询中定义变量名错误更改名称: PHP变量的规则: 1) variable starts with the $ sign, followed by the name of the variable 2) variable nam

我有一个PHP表单,它有许多字段。我想要的是动态地向查询添加字段,根据这些字段的内容在PostgreSQL表中插入值。如果一个字段(如date、int等)为空,我不希望它出现在查询中,因为当我试图插入到表中时,它会在等待插入值时导致“语法错误”。救命啊

编辑


在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);

如果有任何问题,请提一下。

听起来您的查询语法不正确。到目前为止你做了什么?你应该显示你正在构建的代码/查询,以便人们能够提供帮助。可能重复的裁缝,我检查了该链接,但我认为它不一样。那个家伙将字段添加到表中,而不是查询中。艾伦:到目前为止,我提出的问题是正确的。只是一个简单的插入。我想有一个单一的保存按钮,但所有字段都必须有值。如果不是,正如我所解释的,会出现语法错误。请用示例描述您的问题。您已经创建了表plz TINCE.Edited。表格准备好了,里面有记录。我的问题是当我尝试插入新记录时。上面的查询(在PHP中,这就是为什么$)运行正确。如果对应字段中没有pipeID的值,就会发生错误。它是一个预先准备好的语句,因此不需要转义或引用,并且值来自数组$参数=数组(…);那不是我的问题所在。
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);