D
D
dflbrhekbn2017-09-19 13:16:19
PHP
dflbrhekbn, 2017-09-19 13:16:19

How to delete lines in php using checkbox?

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>


<input type="submit" name="formSubmit" value="Удалить" />


<?php

// Подключение login.php
require_once 'login.php';

// Соединение с базой данных
$db_server = mysqli_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("Невозможно подключиться к MySQL: " . mysqli_error());

mysqli_query($db_server,"SET NAMES utf8");

//Выбор базы данных
mysqli_select_db($db_server, $db_database)
or die ("Невозможно выбрать базу данных: " . mysqli_error()); 


$query = "SELECT id,ip_addr,namepc,pass, passadm FROM vlc ORDER BY ip_addr ";  // Сам запрос SQL

$result = mysqli_query($db_server, $query);

echo '<table border="1">';
echo '<thead>';
  echo '<tr>';
  echo '<th>ID</th>';
  echo '<th>IP</th>';
  echo '<th>Имя ПК</th>';
  echo '<th>Пароль</th>';
  echo '<th>Пароль администратора</th>';
  echo '</tr>';
  echo '</thead>';
  echo '<tbody>';


while($data = mysqli_fetch_array($result))
{ 
    echo '<tr>';
    echo '<td>' . $data['id'] . '</td>';
    echo '<td>' . long2ip ($data['ip_addr']) . '</td>';
    echo '<td>' . $data['namepc'] . '</td>';
    echo '<td>' . $data['pass'] . '</td>';
    echo '<td>' . $data['passadm'] . '</td>';
    echo "<td width='10px'><form><input type='checkbox' name='check[]'/></form></td>";
    echo '</tr>';
}

?>

</head>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
leni_m, 2017-09-19
@dflbrhekbn

Maybe so?
and in the handler iterate over the $_POST['check'] array and extract IDs from it.

A
Alexander Lysenko, 2017-09-19
@LysenkoSasha

pass the record id to the value of the checkbox. After clicking on the checkbox, make an Ajax request. Well, or make a button to submit the form.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question