Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770
Форумы портала PHP.SU :: Версия для печати :: Поиск в базе данных - PHP
Форумы портала PHP.SU » PHP » Напишите за меня, пожалуйста » Поиск в базе данных - PHP

Страниц (1): [1]
 

1. gleb162 - 11 Февраля, 2017 - 10:35:06 - перейти к сообщению
Не получается вывести данные из бд через кнопку поиск, в чем ошибка? я хочу чтобы выводились данные через поиск и их можно было бы удалить или отредактировать.
Вот примерно такой формы

PHP:
скопировать код в буфер обмена
  1. <?PHP require_once "head.php"; ?>
  2.  
  3. <?PHP
  4. $isAddClient    = isset($_GET['add_client']);
  5. $isDeleteClient = isset($_GET['delete']);
  6. $isU            = isset($_GET['u']);
  7.  
  8. if($isDeleteClient)
  9. {
  10.     $id = $_GET['delete'];
  11.    
  12.     $stmt = $DBH->prepare("DELETE FROM `clients_table` WHERE `id` = :id");
  13.     $stmt->bindParam(":id", $id);
  14.     $stmt->execute();
  15.    
  16.     header("location: index.php?page=clients");
  17. }
  18. else if($isAddClient)
  19. {
  20.     $fio        = $_GET["client_fio"];
  21.     $phone      = $_GET["client_phone"];
  22.     $carNumber  = $_GET["client_carNumber"];
  23.     $passport   = $_GET["client_passport"];
  24.    
  25.     $stmt = $DBH->prepare("INSERT INTO `clients_table` VALUES(NULL, :fio, :phone, :carNumber, :passport)");
  26.     $stmt->bindParam(":fio", $fio);
  27.     $stmt->bindParam(":phone", $phone);
  28.     $stmt->bindParam(":carNumber", $carNumber);
  29.     $stmt->bindParam(":passport", $passport);
  30.     $stmt->execute();
  31.    
  32.     header("location: index.php?page=clients");
  33. }
  34. else if($isU)
  35. {
  36.     $stmt = $DBH->prepare("UPDATE `clients_table` SET `fio` = :fio, `phone` = :phone, `carNumber` = :car, `passport` = :pass WHERE `id` = :id");
  37.     $stmt->bindParam(":fio", $_GET['fio-1']);
  38.     $stmt->bindParam(":phone", $_GET['phone-1']);
  39.     $stmt->bindParam(":car", $_GET['car-1']);
  40.     $stmt->bindParam(":pass", $_GET['pass-1']);
  41.     $stmt->bindParam(":id", $_GET['id-1']);
  42.     $stmt->execute();
  43.    
  44.     header('location: index.php?page=clients');
  45. }
  46.  
  47. ?>
  48.  
  49. <?PHP
  50. if (isset($_POST['search_buttom'])) {
  51. $car_number = $_POST['search_car_number'];
  52. $stmt = $DBH->prepare("SELECT * FROM `clients_table` WHERE  `carNumber` = :car_number");
  53.     $stmt->bindParam(":car_number", $car_number);
  54.     $stmt->execute();
  55.         echo '<form method="post">
  56.  <input type="text" value="'.$car_number.'" required />
  57.  <input type="submit" value="Добавить" />
  58. </form>';
  59. }
  60. ?>
  61.  
  62. <form method='POST' action='' name='search_form'>
  63. <input type='text' name='search_car_number' value='' placeholder='Введите номер машины'> <input type='submit' name='search_buttom' value='Поиск'>
  64. </form>
  65.  
  66.  
  67. <div class="wrap1">
  68.     <div class="table clients vopros">
  69.         <div class="table-row">
  70.             <div class="table-cell"> # </div>
  71.             <div class="table-cell"> ФИО </div>
  72.             <div class="table-cell"> Тел. номер </div>
  73.             <div class="table-cell"> Номер машины </div>
  74.             <div class="table-cell"> Паспортные данные </div>
  75.             <div class="table-cell"> Действия </div>
  76.         </div>
  77.         <form class="table-row" action="index.php?page=clients" method="get">
  78.             <div class="table-cell">  </div>
  79.             <div class="table-cell"> <input type="text" name="client_fio" placeholder="Петров Петр Петрович" required="on" autocomplete="off"> </div>
  80.             <div class="table-cell"> <input type="text" maxlength="11" onkeyup="this.value = this.value.replace (/[^\d]/g, '')" name="client_phone" placeholder="88005553535" required="on" autocomplete="off"> </div>
  81.             <div class="table-cell"> <input type="text" name="client_carNumber" placeholder="о000оо" required="on" autocomplete="off"> </div>
  82.             <div class="table-cell"> <input type="text" onkeyup="this.value = this.value.replace (/[^\d-]/g, '')" name="client_passport" placeholder="111-123123" required="on" autocomplete="off"> </div>
  83.             <div class="table-cell"> <input type="submit" name="add_client" value="Добавить клиента"> </div>
  84.             <input type="hidden" name="page" value="clients">
  85.         </form>
  86.         <?PHP
  87.         $stmt = $DBH->prepare("SELECT * FROM `clients_table` ORDER BY `id` DESC");
  88.         $stmt->execute();
  89.        
  90.         while($row = $stmt->fetch(PDO::FETCH_OBJ)):
  91.         ?>
  92.         <form class="table-row">
  93.             <div class="table-cell"> <?= $row->id ?> </div>
  94.             <div class="table-cell"> <input type="text" name="fio-1" value="<?= $row->fio ?>" required> </div>
  95.             <div class="table-cell"> <input type="text" maxlength="11" onkeyup="this.value = this.value.replace (/[^\d]/g, '')" name="phone-1" value="<?= $row->phone ?>" required> </div>
  96.             <div class="table-cell"> <input type="text" name="car-1" value="<?= $row->carNumber ?>" required> </div>
  97.             <div class="table-cell"> <input type="text" onkeyup="this.value = this.value.replace (/[^\d-]/g, '')" name="pass-1" value="<?= $row->passport ?>" required> </div>
  98.             <div class="table-cell"> <a class="silka" href="?page=clients&delete=<?= $row->id ?>"> Удалить </a> <input type="submit" name="u" value="Изменить"></div>
  99.             <input type="hidden" name="page" value="clients">
  100.             <input type="hidden" name="id-1" value="<?= $row->id ?>">
  101.         </form>
  102.         <?PHP endwhile; ?>
  103.     </div>
  104. </div>

 

Powered by ExBB FM 1.0 RC1