Доброго времени суток! Подскажите пожалуйста как реализовать функцию редактирования данных через модальное окно
Есть таблица с данными:
HTML5 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| <table class="table table-list-search">
<div class="col col-xs-6">
<h3 class="panel-title">Студенты</h3>
</div>
<div class="col col-xs-6 text-right">
<form action="index.php">
<button type="submit" class="btn btn-sm btn-primary btn-create" href="index.php" >Новая запись</button></form>
</div>
<thead>
<tr>
<th>Имя</th>
<th>Фамилия</th>
<th>Отчество</th>
<th class="text-right">Действие</th>
</tr>
</thead>
<tbody>
<?php while($row1 = mysqli_fetch_array($result)):;?>
<tr>
<td> <?php echo $row1[1];?></td>
<td><?php echo $row1[2];?></td>
<td><?php echo $row1[3];?></td>
<!--- Редактировать ---> <td class="text-right"> <form method="post" action="delete.php">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#product_view"><i class="glyphicon glyphicon-pencil"></i></button>
<!--- Удалить ---> <form method="post" action="delete.php">
<button type= "submit" class='btn btn-danger' name="delete" value="<?=$row1['0']; ?>" > <span class="glyphicon glyphicon-remove"></button></span></form> </td>
</tr>
<?php endwhile;?>
</tbody>
</table> |
|
И модальное окно:
HTML5 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| <div id="product_view" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header"><button class="close" type="button" data-dismiss="modal">×</button>
<h4 class="modal-title">Заголовок окна</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12 product_content">
<form action= "studenti_edit.php" method= "POST">
<div class="form-group">
<h2 class="heading">Ф.И.О.</h2>
<div class="controls">
<input type="text" id="name" class="floatLabel" name="name">
<label for="name">Имя</label>
</div>
<div class="controls">
<input type="text" id="famil" class="floatLabel" name="famil">
<label for="famil">Фамилия</label>
</div>
<div class="controls">
<input type="text" id="otchest" class="floatLabel" name="otchest">
<label for="otchest">Отчество</label>
<div class="modal-footer"><button class="btn btn-default" type="button" data-dismiss="modal" value="<?=$row['0']; ?>" > Подтвердить </button></div>
</div>
</div></form></div>
</div></div></div></div></div> |
|
так же скрипт для редактирования
PHP |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| <?php
require_once 'connection.php';
$link = mysqli_connect($host, $user, $password, $database)
or die("Ошибка " . mysqli_error($link));
$link->set_charset("utf8");
if (isset($_POST['edit'])){
$id = htmlentities(mysqli_real_escape_string($link, $_POST['id']));
$name = htmlentities(mysqli_real_escape_string($link, $_POST['name']));
$famil = htmlentities(mysqli_real_escape_string($link, $_POST['famil']));
$otchest = htmlentities(mysqli_real_escape_string($link, $_POST['otchest']));
$edit=$_POST['edit'];
$query ="UPDATE vse SET name='$name', famil='$famil', otchest='$otchest' WHERE id='$edit'";
$result = mysqli_query($link, $query) or die("Ошибка " . mysqli_error($link));
if($result)
{
header('Location: '.'studenti.php');
}
mysqli_close($link);
}
?> |
|