Insert data from modal to MySQL (multiple modal on website)
I have problem with inserting data to MySQL from modal.
My modal:
<a href="#" class="badge badge-pill badge-success">6 komentarzy</a> <a href="#" class="badge badge-pill badge-danger">brak komentarzy</a>
<a data-toggle="modal" href="#add_desk_comm_{$desk_['desk_id']}" data-target="#add_desk_comm_{$desk_['desk_id']}" class="ediiit">(dodaj)</a>
<div class="modal fade" id="add_desk_comm_{$desk_['desk_id']}" tabindex="-1" role="dialog" aria-labelledby="edit_printer" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Dodaj komentarz do zgłoszenia</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form method="POST" id="fr_{$desk_['desk_id']}" action="".model_load('helpdeskmodel', 'addDeskComm', '')."">
<div class="modal-body">
<table class="table">
<tbody>
<tr>
<td class="border-top-zero label">Data zgłoszenia:</td>
<td colspan="2" class="border-top-zero">
<input type="number" name="add_desk_comm_id" id="inputPlace" value="{$desk_['desk_id']}" class="form-control" autofocus>
</td>
</tr>
<tr>
<td class="border-top-zero label">Data zgłoszenia:</td>
<td colspan="2" class="border-top-zero">
<input type="date" name="add_desk_comm_date" id="inputPlace" class="form-control" autofocus>
</td>
</tr>
<tr>
<td class="border-top-zero label">Komentarz:</td>
<td colspan="2" class="border-top-zero">
<textarea name="add_desk_comm_opis" rows="5" id="inputDate" class="form-control" value="" required="" autofocus="" style="margin-top: 0px; margin-bottom: 0px; height: 249px;"></textarea>
</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Anuluj</button>
<button type="submit_one" name="add_desk_comm_sub_{$desk_['desk_id']}" class="btn btn-warning">Zapisz</button>
</div>
</form>
</div>
</div>
</div>
And form action
public function addDeskComm()
{
if(isset($this->__params['POST']['add_desk_comm_id']))
{
$add_desk_comm_id = $this->__params['POST']['add_desk_comm_id'];
$add_desk_comm_date = $this->__params['POST']['add_desk_comm_date'];
$add_desk_comm_opis = $this->__params['POST']['add_desk_comm_opis'];
$res = $this->__db->execute("INSERT INTO helpdesk_history (id, id_helpdesk, date, opis) SELECT NULL, '{$add_desk_comm_id}', '{$add_desk_comm_date}', '{$add_desk_comm_opis}' UNION ALL SELECT NULL, '{$add_desk_comm_id}', '{$add_desk_comm_date}', '{$add_desk_comm_opis}' LIMIT 1;");
}
return false;
}
Modal is in foreach and is repeated on the website (every row in the table has a modal). if you want to insert data into the mysql database, modal is executed as many times as there are rows in the table on the website. even modal id change does not help.
Any idea? I will add that I use only js bootstrap.
javascript php mysql
add a comment |
I have problem with inserting data to MySQL from modal.
My modal:
<a href="#" class="badge badge-pill badge-success">6 komentarzy</a> <a href="#" class="badge badge-pill badge-danger">brak komentarzy</a>
<a data-toggle="modal" href="#add_desk_comm_{$desk_['desk_id']}" data-target="#add_desk_comm_{$desk_['desk_id']}" class="ediiit">(dodaj)</a>
<div class="modal fade" id="add_desk_comm_{$desk_['desk_id']}" tabindex="-1" role="dialog" aria-labelledby="edit_printer" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Dodaj komentarz do zgłoszenia</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form method="POST" id="fr_{$desk_['desk_id']}" action="".model_load('helpdeskmodel', 'addDeskComm', '')."">
<div class="modal-body">
<table class="table">
<tbody>
<tr>
<td class="border-top-zero label">Data zgłoszenia:</td>
<td colspan="2" class="border-top-zero">
<input type="number" name="add_desk_comm_id" id="inputPlace" value="{$desk_['desk_id']}" class="form-control" autofocus>
</td>
</tr>
<tr>
<td class="border-top-zero label">Data zgłoszenia:</td>
<td colspan="2" class="border-top-zero">
<input type="date" name="add_desk_comm_date" id="inputPlace" class="form-control" autofocus>
</td>
</tr>
<tr>
<td class="border-top-zero label">Komentarz:</td>
<td colspan="2" class="border-top-zero">
<textarea name="add_desk_comm_opis" rows="5" id="inputDate" class="form-control" value="" required="" autofocus="" style="margin-top: 0px; margin-bottom: 0px; height: 249px;"></textarea>
</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Anuluj</button>
<button type="submit_one" name="add_desk_comm_sub_{$desk_['desk_id']}" class="btn btn-warning">Zapisz</button>
</div>
</form>
</div>
</div>
</div>
And form action
public function addDeskComm()
{
if(isset($this->__params['POST']['add_desk_comm_id']))
{
$add_desk_comm_id = $this->__params['POST']['add_desk_comm_id'];
$add_desk_comm_date = $this->__params['POST']['add_desk_comm_date'];
$add_desk_comm_opis = $this->__params['POST']['add_desk_comm_opis'];
$res = $this->__db->execute("INSERT INTO helpdesk_history (id, id_helpdesk, date, opis) SELECT NULL, '{$add_desk_comm_id}', '{$add_desk_comm_date}', '{$add_desk_comm_opis}' UNION ALL SELECT NULL, '{$add_desk_comm_id}', '{$add_desk_comm_date}', '{$add_desk_comm_opis}' LIMIT 1;");
}
return false;
}
Modal is in foreach and is repeated on the website (every row in the table has a modal). if you want to insert data into the mysql database, modal is executed as many times as there are rows in the table on the website. even modal id change does not help.
Any idea? I will add that I use only js bootstrap.
javascript php mysql
You should have only one modal. Its not a good practice to have loop modal on your page. What if you have a thousand row there. Best option is to create an onlick function in javascript that gets the row id and its data. Then you trigger that modal and transfer the data to the form inside the the modal. What is the error you have encountered?
– Renzchler
Nov 28 '18 at 6:40
Error? Submit is done as many times as there are rows in the table (this is how many times the insert is made to the database). Instead of inserting one row into the database, it puts a lot of them (as if one submit performed all the modals)
– k_turek
Nov 28 '18 at 7:08
I don't get what you are trying to achieve. So the problem is that it inserts multiple row instead of one row from which the form is submitted from?Example I clicked row 1 only, then the rows 2 3 4 5 is inserted also. And what you want is the row 1 only to be inserted?. Am I correct?
– Renzchler
Nov 28 '18 at 7:26
Almost... In the lines there are applications to which (via modal) wants to add comments. Each row (that is, each entry) has its own modal to add a comment. If I add it, in the database it inserts X comments (X = number of entries / rows) of the same.
– k_turek
Nov 28 '18 at 7:45
add a comment |
I have problem with inserting data to MySQL from modal.
My modal:
<a href="#" class="badge badge-pill badge-success">6 komentarzy</a> <a href="#" class="badge badge-pill badge-danger">brak komentarzy</a>
<a data-toggle="modal" href="#add_desk_comm_{$desk_['desk_id']}" data-target="#add_desk_comm_{$desk_['desk_id']}" class="ediiit">(dodaj)</a>
<div class="modal fade" id="add_desk_comm_{$desk_['desk_id']}" tabindex="-1" role="dialog" aria-labelledby="edit_printer" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Dodaj komentarz do zgłoszenia</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form method="POST" id="fr_{$desk_['desk_id']}" action="".model_load('helpdeskmodel', 'addDeskComm', '')."">
<div class="modal-body">
<table class="table">
<tbody>
<tr>
<td class="border-top-zero label">Data zgłoszenia:</td>
<td colspan="2" class="border-top-zero">
<input type="number" name="add_desk_comm_id" id="inputPlace" value="{$desk_['desk_id']}" class="form-control" autofocus>
</td>
</tr>
<tr>
<td class="border-top-zero label">Data zgłoszenia:</td>
<td colspan="2" class="border-top-zero">
<input type="date" name="add_desk_comm_date" id="inputPlace" class="form-control" autofocus>
</td>
</tr>
<tr>
<td class="border-top-zero label">Komentarz:</td>
<td colspan="2" class="border-top-zero">
<textarea name="add_desk_comm_opis" rows="5" id="inputDate" class="form-control" value="" required="" autofocus="" style="margin-top: 0px; margin-bottom: 0px; height: 249px;"></textarea>
</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Anuluj</button>
<button type="submit_one" name="add_desk_comm_sub_{$desk_['desk_id']}" class="btn btn-warning">Zapisz</button>
</div>
</form>
</div>
</div>
</div>
And form action
public function addDeskComm()
{
if(isset($this->__params['POST']['add_desk_comm_id']))
{
$add_desk_comm_id = $this->__params['POST']['add_desk_comm_id'];
$add_desk_comm_date = $this->__params['POST']['add_desk_comm_date'];
$add_desk_comm_opis = $this->__params['POST']['add_desk_comm_opis'];
$res = $this->__db->execute("INSERT INTO helpdesk_history (id, id_helpdesk, date, opis) SELECT NULL, '{$add_desk_comm_id}', '{$add_desk_comm_date}', '{$add_desk_comm_opis}' UNION ALL SELECT NULL, '{$add_desk_comm_id}', '{$add_desk_comm_date}', '{$add_desk_comm_opis}' LIMIT 1;");
}
return false;
}
Modal is in foreach and is repeated on the website (every row in the table has a modal). if you want to insert data into the mysql database, modal is executed as many times as there are rows in the table on the website. even modal id change does not help.
Any idea? I will add that I use only js bootstrap.
javascript php mysql
I have problem with inserting data to MySQL from modal.
My modal:
<a href="#" class="badge badge-pill badge-success">6 komentarzy</a> <a href="#" class="badge badge-pill badge-danger">brak komentarzy</a>
<a data-toggle="modal" href="#add_desk_comm_{$desk_['desk_id']}" data-target="#add_desk_comm_{$desk_['desk_id']}" class="ediiit">(dodaj)</a>
<div class="modal fade" id="add_desk_comm_{$desk_['desk_id']}" tabindex="-1" role="dialog" aria-labelledby="edit_printer" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Dodaj komentarz do zgłoszenia</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form method="POST" id="fr_{$desk_['desk_id']}" action="".model_load('helpdeskmodel', 'addDeskComm', '')."">
<div class="modal-body">
<table class="table">
<tbody>
<tr>
<td class="border-top-zero label">Data zgłoszenia:</td>
<td colspan="2" class="border-top-zero">
<input type="number" name="add_desk_comm_id" id="inputPlace" value="{$desk_['desk_id']}" class="form-control" autofocus>
</td>
</tr>
<tr>
<td class="border-top-zero label">Data zgłoszenia:</td>
<td colspan="2" class="border-top-zero">
<input type="date" name="add_desk_comm_date" id="inputPlace" class="form-control" autofocus>
</td>
</tr>
<tr>
<td class="border-top-zero label">Komentarz:</td>
<td colspan="2" class="border-top-zero">
<textarea name="add_desk_comm_opis" rows="5" id="inputDate" class="form-control" value="" required="" autofocus="" style="margin-top: 0px; margin-bottom: 0px; height: 249px;"></textarea>
</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Anuluj</button>
<button type="submit_one" name="add_desk_comm_sub_{$desk_['desk_id']}" class="btn btn-warning">Zapisz</button>
</div>
</form>
</div>
</div>
</div>
And form action
public function addDeskComm()
{
if(isset($this->__params['POST']['add_desk_comm_id']))
{
$add_desk_comm_id = $this->__params['POST']['add_desk_comm_id'];
$add_desk_comm_date = $this->__params['POST']['add_desk_comm_date'];
$add_desk_comm_opis = $this->__params['POST']['add_desk_comm_opis'];
$res = $this->__db->execute("INSERT INTO helpdesk_history (id, id_helpdesk, date, opis) SELECT NULL, '{$add_desk_comm_id}', '{$add_desk_comm_date}', '{$add_desk_comm_opis}' UNION ALL SELECT NULL, '{$add_desk_comm_id}', '{$add_desk_comm_date}', '{$add_desk_comm_opis}' LIMIT 1;");
}
return false;
}
Modal is in foreach and is repeated on the website (every row in the table has a modal). if you want to insert data into the mysql database, modal is executed as many times as there are rows in the table on the website. even modal id change does not help.
Any idea? I will add that I use only js bootstrap.
javascript php mysql
javascript php mysql
edited Nov 28 '18 at 8:11
Renzchler
7510
7510
asked Nov 28 '18 at 6:28
k_turekk_turek
195
195
You should have only one modal. Its not a good practice to have loop modal on your page. What if you have a thousand row there. Best option is to create an onlick function in javascript that gets the row id and its data. Then you trigger that modal and transfer the data to the form inside the the modal. What is the error you have encountered?
– Renzchler
Nov 28 '18 at 6:40
Error? Submit is done as many times as there are rows in the table (this is how many times the insert is made to the database). Instead of inserting one row into the database, it puts a lot of them (as if one submit performed all the modals)
– k_turek
Nov 28 '18 at 7:08
I don't get what you are trying to achieve. So the problem is that it inserts multiple row instead of one row from which the form is submitted from?Example I clicked row 1 only, then the rows 2 3 4 5 is inserted also. And what you want is the row 1 only to be inserted?. Am I correct?
– Renzchler
Nov 28 '18 at 7:26
Almost... In the lines there are applications to which (via modal) wants to add comments. Each row (that is, each entry) has its own modal to add a comment. If I add it, in the database it inserts X comments (X = number of entries / rows) of the same.
– k_turek
Nov 28 '18 at 7:45
add a comment |
You should have only one modal. Its not a good practice to have loop modal on your page. What if you have a thousand row there. Best option is to create an onlick function in javascript that gets the row id and its data. Then you trigger that modal and transfer the data to the form inside the the modal. What is the error you have encountered?
– Renzchler
Nov 28 '18 at 6:40
Error? Submit is done as many times as there are rows in the table (this is how many times the insert is made to the database). Instead of inserting one row into the database, it puts a lot of them (as if one submit performed all the modals)
– k_turek
Nov 28 '18 at 7:08
I don't get what you are trying to achieve. So the problem is that it inserts multiple row instead of one row from which the form is submitted from?Example I clicked row 1 only, then the rows 2 3 4 5 is inserted also. And what you want is the row 1 only to be inserted?. Am I correct?
– Renzchler
Nov 28 '18 at 7:26
Almost... In the lines there are applications to which (via modal) wants to add comments. Each row (that is, each entry) has its own modal to add a comment. If I add it, in the database it inserts X comments (X = number of entries / rows) of the same.
– k_turek
Nov 28 '18 at 7:45
You should have only one modal. Its not a good practice to have loop modal on your page. What if you have a thousand row there. Best option is to create an onlick function in javascript that gets the row id and its data. Then you trigger that modal and transfer the data to the form inside the the modal. What is the error you have encountered?
– Renzchler
Nov 28 '18 at 6:40
You should have only one modal. Its not a good practice to have loop modal on your page. What if you have a thousand row there. Best option is to create an onlick function in javascript that gets the row id and its data. Then you trigger that modal and transfer the data to the form inside the the modal. What is the error you have encountered?
– Renzchler
Nov 28 '18 at 6:40
Error? Submit is done as many times as there are rows in the table (this is how many times the insert is made to the database). Instead of inserting one row into the database, it puts a lot of them (as if one submit performed all the modals)
– k_turek
Nov 28 '18 at 7:08
Error? Submit is done as many times as there are rows in the table (this is how many times the insert is made to the database). Instead of inserting one row into the database, it puts a lot of them (as if one submit performed all the modals)
– k_turek
Nov 28 '18 at 7:08
I don't get what you are trying to achieve. So the problem is that it inserts multiple row instead of one row from which the form is submitted from?Example I clicked row 1 only, then the rows 2 3 4 5 is inserted also. And what you want is the row 1 only to be inserted?. Am I correct?
– Renzchler
Nov 28 '18 at 7:26
I don't get what you are trying to achieve. So the problem is that it inserts multiple row instead of one row from which the form is submitted from?Example I clicked row 1 only, then the rows 2 3 4 5 is inserted also. And what you want is the row 1 only to be inserted?. Am I correct?
– Renzchler
Nov 28 '18 at 7:26
Almost... In the lines there are applications to which (via modal) wants to add comments. Each row (that is, each entry) has its own modal to add a comment. If I add it, in the database it inserts X comments (X = number of entries / rows) of the same.
– k_turek
Nov 28 '18 at 7:45
Almost... In the lines there are applications to which (via modal) wants to add comments. Each row (that is, each entry) has its own modal to add a comment. If I add it, in the database it inserts X comments (X = number of entries / rows) of the same.
– k_turek
Nov 28 '18 at 7:45
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53513384%2finsert-data-from-modal-to-mysql-multiple-modal-on-website%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53513384%2finsert-data-from-modal-to-mysql-multiple-modal-on-website%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You should have only one modal. Its not a good practice to have loop modal on your page. What if you have a thousand row there. Best option is to create an onlick function in javascript that gets the row id and its data. Then you trigger that modal and transfer the data to the form inside the the modal. What is the error you have encountered?
– Renzchler
Nov 28 '18 at 6:40
Error? Submit is done as many times as there are rows in the table (this is how many times the insert is made to the database). Instead of inserting one row into the database, it puts a lot of them (as if one submit performed all the modals)
– k_turek
Nov 28 '18 at 7:08
I don't get what you are trying to achieve. So the problem is that it inserts multiple row instead of one row from which the form is submitted from?Example I clicked row 1 only, then the rows 2 3 4 5 is inserted also. And what you want is the row 1 only to be inserted?. Am I correct?
– Renzchler
Nov 28 '18 at 7:26
Almost... In the lines there are applications to which (via modal) wants to add comments. Each row (that is, each entry) has its own modal to add a comment. If I add it, in the database it inserts X comments (X = number of entries / rows) of the same.
– k_turek
Nov 28 '18 at 7:45