Hello. I have a JavaScript in the form that dynamically adds an input field to the form. The newly added field has the following attributes:
<input value="<?=$prp['name'];?>" name="prpunkt[]<?=$ipp?>" type="text" /> where $ prp ['name'] is the text from the base. $ ipp - $ipp++ ;
The task is this, you need to make editing existing fields in the database, and adding new ones.
And everything would be fine, but. Each field is attached to a specific article. Table structure with fields:
id -
AUTO_INCREMENTtrip
INT- id of the article to which we bind the fieldname
varchar- field values ββ(text in the field)
An indefinite number of fields may be attached to the article.
When editing an article, it is possible to edit already existing add. fields and create new ones.
Already existing fields, when editing the article, I display the cycle:
while ($prp = mysql_fetch_assoc($option_prp)) { $ipp++; //echo $ipp; ?> <div><input class="stationinppp" value="<?=$prp['name'];?>" name="prpunkt[]<?=$ipp?>" type="text" /></div> <? } That is, it turns out that if this article is added, for example, 3 additional. fields, the markup is as follows:
<input value="<?=$prp['name'];?>" name="prpunkt[]1" type="text" /> <input value="<?=$prp['name'];?>" name="prpunkt[]2" type="text" /> <input value="<?=$prp['name'];?>" name="prpunkt[]3" type="text" /> And the newly added field has markup:
<input value="<?=$prp['name'];?>" name="prpunkt[]4" type="text" /> <input value="<?=$prp['name'];?>" name="prpunkt[]5" type="text" /> The value of name - name="prpunkt[]+1"
How can I determine on the server, which field has been changed, and which field has been added? This is for me to perform the corresponding requests to the database, to the new field INSERT INTO - write a new line to the base / to the modified field UPDATE - update the record.
The data from the fields on the server is caught as follows:
foreach ($_POST['prpunkt'] as $k => $f) { echo $_POST['prpunkt'][$k]; }
INSERT ON DUPLICATE KEY UPDATE? - Alexey Shimanskyprom_item(trip,name) values ββ('$ nw_id', '$ namepp') ON DUPLICATE KEY UPDATE name = '$ namepp'"); The name field is unique. but when you edit a field, a new one is added. What am I missing? - iKey