JavaScript — Как редактировать и добавлять одновременно с помощью одной кнопки (PHP)

У меня была проблема с моим кодом SQL.
Мне удается создать функцию добавления и редактирования в Кнопка ONE SAVE при использовании одно поле но не удалось если я добавлю больше поля. Я могу добавить это отлично, но не могу редактировать поле.

Моя ситуация заключается в том, что мне нужно добавить опыт, если опыт пуст, мне нужно будет добавить новый опыт, или, если бы я добавил, я могу добавить больше опыта и редактировать его.

это мой код в форме опыта

      <form class="form-horizontal form-label-left" method="post" >

<div class="form-group">
<div align="center">
<table align="center" cellspacing="0">
<tr>
<td><strong>Accreditation Body </strong></td>
<td><strong for="institution">Type of Auditor</strong></td>
<td><div align="center"><strong>Year of Experience (example : 2000-2002)</strong></div></td>
<td></td>
</tr>
<?php
$i = 0;

foreach ($exps as $exp)
// foreach (array_slice($exps,1) as $exp)
{?>
<tr>
<td>  <textarea id="description" required="required" name="description[example<?php echo ++$i;?>]" class="form-control col-md-7 col-xs-12"><?php echo $exp['description'];?></textarea></td>
<td>

<select class="form-control" type="" id="institution" name="institution[example<?php echo ++$i;?>]" required>
<option></option>
<option value="External Auditor" <?php echo helpers::selectValueEdit("External Auditor", "institution[]", $exp['institution']);?>>External Auditor</option>
<option value="Internal Auditor" <?php echo helpers::selectValueEdit("Internal Auditor", "institution[]", $exp['institution']);?>>Internal Auditor</option>
</select>


</td>
<td>


<input type="text" id="year" name="year[example<?php echo ++$i;?>]" required="required" class="form-control col-md-7 col-xs-12" value="<?php echo $exp['year'];?>">
</td>

<input type="hidden" name="id[example<?php echo $i;?>]" value="<?php echo $exp['experience_id'];?>"/td>

<td>


</form>
<script>
<?php
$input = '\'
<div class="control-group input-group" style="margin-top:10px">
<div align="right_col">
<table align="" cellspacing="0">


<tr>

<td>  <textarea id="description" type="text" required="required" name="description[]" class="form-control "></textarea></td>

<td>

<select class="form-control"  type="text" id="institution" name="institution[]"  required>
<option></option>
<option value="External Auditor">External Auditor</option>
<option value="Internal Auditor">Internal Auditor</option>
</select>
</td>
<td>  <input type="text" id="year" name="year[]" required="required" class="form-control" >
</td>
<td>
<div class="input-group-btn">
<button class="btn btn-danger remove" type="button"><i class="glyphicon glyphicon-remove"></i> Remove</button>
</div>

</td>
</tr>


<input type="" name="txt_holder" id="txt_holder" hidden>


</table>
</div>

</div>\'';

$input = preg_replace( "/\r|\n/", "", $input );
?>
function addNew() {

$("#insert-after").append(<?php echo $input;?>);

if ($("#edit-button").hasClass("hidden")){
$("#edit-button").removeClass("hidden");
}
}


</script>
<!-- page content -->
<div class="right_col" role="main">
<div class="">
<div class="page-title">
<div class="title_left">
<h3>Edit Profile</h3>
</div>


</div>
<div class="clearfix"></div>

<div class="row">

<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<?php session::display_msg();?>
<h2>Experience</h2>

<div class="clearfix"></div>
</div>
<div class="x_content">

<form class="form-horizontal form-label-left" method="post" >

<div class="form-group">
<div align="center">
<table align="center" cellspacing="0">
<tr>
<td><strong>Accreditation Body </strong></td>
<td><strong for="institution">Type of Auditor</strong></td>
<td><div align="center"><strong>Year of Experience (example : 2000-2002)</strong></div></td>
<td></td>
</tr>
<?php
$i = 0;

foreach ($exps as $exp)
// foreach (array_slice($exps,1) as $exp)
{?>
<tr>
<td>  <textarea id="description" required="required" name="description[example<?php echo ++$i;?>]" class="form-control col-md-7 col-xs-12"><?php echo $exp['description'];?></textarea></td>
<td>

<select class="form-control" type="" id="institution" name="institution[example<?php echo ++$i;?>]" required>
<option></option>
<option value="External Auditor" <?php echo helpers::selectValueEdit("External Auditor", "institution[]", $exp['institution']);?>>External Auditor</option>
<option value="Internal Auditor" <?php echo helpers::selectValueEdit("Internal Auditor", "institution[]", $exp['institution']);?>>Internal Auditor</option>
</select>


</td>
<td>


<input type="text" id="year" name="year[example<?php echo ++$i;?>]" required="required" class="form-control col-md-7 col-xs-12" value="<?php echo $exp['year'];?>">
</td>

<input type="hidden" name="id[example<?php echo $i;?>]" value="<?php echo $exp['experience_id'];?>"/td>

<td>


<a href="delete_admin.php?exp=<?php echo $exp['experience_id'];?>&p_id=<?php echo $exp['exp_id']; ?>" name="delete" class="btn btn-sm btn-danger" id="delete-button">Delete</a>







</td>
</tr>



</table>
<div id="insert-after"></div>
<a href="" onclick="addNew();return false;"  class="btn btn-success" >Add New</a>


<input type="submit" name="edit" value="Save" class="btn btn-success" id="edit-button">



</form>

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector