1
I have a form in html that has a field where the user goes inserting the data as it shows the code below, this form is dynamic and the user can insert as much information as he wants, in the following case I put only six systems.
My question is: How will I receive this amount of information in PHP by $_POST and insert it into the database? The query I can do, but I know I have to work with a repetition structure, but how?
HTML code:
<div id="container">
<ul class="tags">
<li class="addedTag">
sistema1
<span class="tagRemove" onclick="$(this).parent().remove();">x</span>
<input type="hidden" value="sistema1" name="tags[]"/>
</li>
<li class="addedTag">
sistema2
<span class="tagRemove" onclick="$(this).parent().remove();">x</span>
<input type="hidden" value="sistema2" name="tags[]"/>
</li>
<li class="addedTag">
sistema3
<span class="tagRemove" onclick="$(this).parent().remove();">x</span>
<input type="hidden" value="sistema3" name="tags[]"/>
</li>
<li class="addedTag">
sistema4
<span class="tagRemove" onclick="$(this).parent().remove();">x</span>
<input type="hidden" value="sistema4" name="tags[]"/>
</li>
<li class="addedTag">
sistema5
<span class="tagRemove" onclick="$(this).parent().remove();">x</span>
<input type="hidden" value="sistema5" name="tags[]"/>
</li>
<li class="addedTag">
sistema6
<span class="tagRemove" onclick="$(this).parent().remove();">x</span>
<input type="hidden" value="sistema6" name="tags[]"/>
</li>
<li class="tagAdd taglist">
<input type="text" id="search-field"/>
</li>
</ul>
</div>
PHP:
<?php
$tags = $_POST['tags'];
$query = mysqli_query($dbc, ""INSERT INTO tb_conhecimentos .......
?>
The data is written but I noticed that if I use FOREACH I can’t insert the data directly in the database right... pq from php error "Catchable fatal error: Object of class mysqli_result could not be converted to string in" ... using "$query = mysqli_query($dbc, "INSERT INTO tb_tag (tag_id, tag_knowledge_id, tag_name) VALUES (NULL, '$query','$tags');");"
– Igor Santana
If you’re doing it wrong inside the
foreach
takes the $value variable and inserts intag_nome
! the way you’re wrong anyway.– novic
the boy. and truth... I falter my! but still cotninua giving the message
"Catchable fatal error: Object of class mysqli_result could not be converted to string in C:\xampp\htdocs\base\incluir_validacao.php on line 113"
.... now the code is like this:$query_insert = mysqli_query($dbc, "INSERT INTO tb_tag (tag_id, tag_conhecimento_id, tag_nome) VALUES (NULL, '$query','$value');");
– Igor Santana
what’s inside the
$query
? can be like this if tag_id is auto_incrementmysqli_query($dbc, "INSERT INTO tb_tag (tag_conhecimento_id, tag_nome) VALUES ('$query','$value');");
– novic
Boy... you killed the syrup! I took $query and used only $value and it inserted... but what $query brings is the last value that was inserted in another table!
– Igor Santana
so, it’s something on your record that’s missing !!!
– novic
Really... I’m going to poke around here! Thanks for the help!!!
– Igor Santana