I am using postgis for my project along with geoserver and openlayers. I give user an html form with drop down menu list of available layers(each layer corresponds to a table in db).The user can select any layer , based on which I am retrieving the fields of that particular from db to insert the values. As soon as the user inputs data and clicks on submit then the data should be inserted into db.
Inserting data into db is a trivial thing as far as you know the order in which to insert into the db. But I have tables with different number of fields and in different order. I want to know how can I insert values into particular table when I don't know the order in which I have to store.
I shall explain with an example:
Table 1 of layer1: id,name,point Table 2 of layer2: id,polygon,name,area
When user selects layer1 in dropdown menu , the form will provide you id,name,point text fields in that order to insert data. If the user selects layer2 then form will give you id,polygon,name,area text fields in that order. Suppose say user has selected layer1 then after inserting the values into text fields and submitting , the php file should perform a query "insert into (id,name,point) values('$_post[id]','$_post[name]','st_geomfromtext('POINT($_post[point])',4326));"
Same way for inserting into layer2 the query should be "insert into (id,polygon,name,area) values('$_post[id]','st_geomfromtext('POINT($_post[point])',4326),'$_post[name]','$_post[area]');"
But how can I know that I have to use only this particular query??? I can know the table name from hidden field.
For now my php file is like this:
$tablename=$_POST[tablename]; if($tablename=='layer1') { perform query1; } else if($tablename=='layer2') { perform query2; }
But this works only if I know the tables already present. Is there anyway to write the php file provided I know only the table name but no idea of table description in db?? (I can get the table description through a query if I want).