D
D
desertsvam2020-05-14 17:26:08
PHP
desertsvam, 2020-05-14 17:26:08

The entry in the database is not deleted through a php request, what is the error?

Hello, I'm asking for help from those in the know.
I made a page that displays records from the database, made a button to delete a record, when you click the page is updated and the result is 0, there are no errors.
Please tell me how to change the request so that it works, thanks.

<?php 
require_once "../lib/orders_class.php";

//Заявки
$class=new Orders;
$filtermasterr=$class->database->select("users", "id>0");
for ($i=0; $i<count($filtermasterr); $i++){
  $filtermaster.="<li><a href='?master=".$filtermasterr[$i][id]."'>".$filtermasterr[$i][username]."</a></li>";
  if ($filtermasterr[$i][id]==$_GET[master])$filteruser=$filtermasterr[$i][username];
  }
  
//Удалить
if ($_GET[delete]){
  $error=$class->delete("order", "id='".$_GET[deleteorders]."'");
  if ($error=="1") echo "<meta http-equiv='Refresh' content='0; URL=/order/'>";
  }	
//вывод по статусу
if ($_GET[status]){
  $where="status='".$_GET[status]."'";
  $status=array("1"=>"В ожидании", "2"=>"Заказ запчасти", "3"=>"Повтор", "4"=>"Выполнено");
  $filter=$status[$_GET[status]];
  }
  
//вывод по дате
if ($_GET[data]){$where="data='".$_GET[data]."'"; $data=$_GET[data];}
else $data=date("Y-m-d");

//вывод по поиску
if ($_GET[search])$where="address like '%".$_GET[search]."%' or telefon like '%".$_GET[search]."%'"; 

//вывод по мастеру
if ($_GET[master])$where="master='".$_GET[master]."'";	
  
$text=$class->selectorders($where);
if ($_GET) $add="<a class='btn btn-danger' href='/orders/'>Показать все</a>";
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Заявки</title>
    <?php require_once "../blog/head.php"; ?>
  </head>
  <body>
  <?php require_once "../blog/menu.php"; ?> 
    <div class="container-fluid">
      <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
      <?php require_once "../blog/satebar.php"; ?>
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
          <h1 class="page-header">Заявки</h1>
          <?=$error?>
          <div class="row">
             <div class="col-md-6">		    
        <a href="add.php" class="btn btn-success"><span class="glyphicon glyphicon-plus-sign"></span> Добавить</a>  
        <div class="btn-group">
          <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false" title="фильтр по статусу">
          <span class="glyphicon glyphicon-filter"></span> <?=$filter?>
          </button>
          <ul class="dropdown-menu" role="menu">
          <li><a href="?status=1">В ожидании</a></li>
          <li><a href="?status=2">Заказ запчасти</a></li>
          <li><a href="?status=3">Повтор</a></li>
          <li><a href="?status=4">Выполнено</a></li>
          </ul>
        </div>
        <div class="btn-group">
          <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false" title="фильтр по мастеру">
          <span class="glyphicon glyphicon-user"></span> <?=$filteruser?>
          </button>
          <ul class="dropdown-menu" role="menu">
          <?=$filtermaster?>
          </ul>
        </div>
        <a href="#" class="btn btn-default" onclick="window.print()" title="печать таблицы заявок"><span class="glyphicon glyphicon-print"></span></a>
        <?=$add?>
        <p></p>
       </div>
       <div class="col-md-3 text-right">
         <form method="get" action="" class="form-inline">
           <input type="date" name="data" class="form-control" required value="<?=$data?>" onchange="this.form.submit()">
         </form>
         <p></p>
         </div>
       <div class="col-md-3 text-right">	
          <form method="get" action="" class="form-inline">
          <div class="input-group">
            <input type="search" name="search" class="form-control" value="<?=$_GET['search']?>" placeholder="Найти...">
            <span class="input-group-btn">
            <button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-search"></span></button>
            </span>
          </div> 
          </form>
          <p></p>
       </div>
      </div>         
          <div class="table-responsive ">
            <table class="table table-bordered table-hover">
              <thead>
                <tr>
                  <th>Дата</th>
                  <th>Адрес</th>
                  <th>Телефон</th>
                  <th>Техника</th>
                  <th>Бренд</th>
                  <th>Неисправность</th> 
                  <th style="width: 150px"></th>               
                </tr>
              </thead>
              <tbody>
                <?=$text?>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  <?php require_once "../blog/footer.php"; ?> 
</body>
</html>

Here is the delete function written in a separate file.
<?php
require_once "user_class.php";
class Orders{
  
    public function __construct(){
      $this->database = new DataBase();
      $this->config = new Config();
    }

    public function __destruct(){
        $this->database = null;
    }
    
//СОХРАНИТЬ

  public function insertorders($data, $address, $telefon, $tehnica, $brend, $defect, $master, $model, $datawork){ 
    $result=$this->database->insert("orders","data, address, telefon, id_tehnika, id_brend, defect, status, master, model, datawork","'".$data."', '".$address."', '".$telefon."', '".$tehnica."', '".$brend."', '".$defect."', '1', '".$master."', '".$model."', '".$datawork."'");
    return $result;
    }	
    
//ВЫВЕСТИ

  public function selectorders($where){
    $accessuser=$this->database->select("users", "id='".$_SESSION["user_id"]."'");
    if ($accessuser[0]["access"]=="Мастер"){
      if ($where=="")$where="id>0 and master='".$_SESSION["user_id"]."'";
      $result=$this->database->select("orders", " ".$where." and master='".$_SESSION["user_id"]."' order by data desc");		
    }
    else {
      if ($where=="")$where="id>0";
      $result=$this->database->select("orders", " ".$where." order by data desc");
    }
    for ($i=0;$i<count($result);$i++){
      $tehnika=$this->database->select("tehnika", "id='".$result[$i][id_tehnika]."'");
      $brend=$this->database->select("brend", "id='".$result[$i][id_brend]."'");
      $class="";
      if ($result[$i][status]==1) $class="class='danger'";
      if ($result[$i][status]==2) $class="class='warning'";
      if ($result[$i][status]==3) $class="class='info'";
      if ($result[$i][status]==4) $class="class='success'";
      $data=$this->config->getRusDate($result[$i][data]);
      $text.="<tr ".$class.">
          <td>".$data."</td>
          <td>".$result[$i][address]."</td>
          <td>".$result[$i][telefon]."</td>
          <td>".$tehnika[0][name]."</td>
          <td>".$brend[0][name]."</td>
          <td>".$result[$i][defect]."</td>
          <td><a href='edit.php?id=".$result[$i][id]."' class='btn btn-default'><span class='glyphicon glyphicon-pencil'></span></a> <a href='?delete=".$result[$i][id]."'  onClick='return window.confirm(\"Удалить заказ?\")' class='btn btn-default'><span class='glyphicon glyphicon-trash'></span></a></td>
                   </tr>";
      }
    return $text;
    }
    
//УДАЛИТЬ

  public function deleteorders($id){
    $error=$this->database->delete("orders", "id='".$id."'");	
    return $result;
    }
    
//ИЗМЕНИТЬ

  public function updateorders($id, $data, $address, $telefon, $tehnika, $brend, $defect, $status, $master, $model){
    $result=$this->database->update("orders", "data='".$data."', address='".$address."', telefon='".$telefon."', id_tehnika='".$tehnika."', id_brend='".$brend."', defect='".$defect."', status='".$status."', master='".$master."', model='".$model."' where id='".$id."'");	
    return $result;
    }	
    																
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question