0

Здравствуйте столкнулся с проблемой, что не работает переадресация на другую страницу в php выдает ошибку со скриншота. Как можно исправить?[![

*,
*::before,
*::after {
  scroll-behavior: smooth;
  padding: 0;
  margin: 0;
  border: 0;
  box-sizing: border-box;
}

a {
  text-decoration: none;
  color: #fff;
}

ol,
ul,
li {
  list-style: none;
}

img {
  vertical-align: top;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: inherit;
  font-size: inherit;
}

body {
  height: 100%;
  line-height: 1;
  background-color: antiquewhite;
}


/* Стили текста(Общий) */

.text {
  color: #111;
  font-family: "Oswald";
  padding: .4rem;
}

.table-block {
  border: .09rem solid rgb(255, 166, 0);
  padding: 1rem;
}

table {
  margin: auto;
  border: .3rem solid rgb(255, 166, 0);
  border-radius: .6rem;
  border-spacing: 0px;
  border-collapse: collapse;
  padding: 1rem;
}

th {
  border: .2rem solid rgb(255, 166, 0);
  padding: 1rem;
}

.logo {
  width: 20rem;
  height: 15rem;
}

.main-section {
  display: flex;
  justify-content: space-around;
  padding: 1rem;
}

.table-btn {
  background-color: antiquewhite;
}

.add-btn {
  display: block;
  margin: auto;
  border: .2rem solid rgb(255, 166, 0);
  padding: 1rem;
  background-color: antiquewhite;
  border-radius: .6rem;
  margin-top: 1rem;
}
<?php 
    $startReadFilePow = 0;  
    $all = array();
    if (($file = fopen("data.csv", "r")) !== FALSE) { 
        while (($data = fgetcsv($file, 1000, ';')) !== FALSE) { 
            $dataFromCSV = array();
            for ($c=0; $c < count($data); $c++) {
                array_push($dataFromCSV, $data[$c]);
            }
            array_push($all, $dataFromCSV);
            $startReadFilePow++;   
        }
        fclose($file);
    }
   

?>


<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,300;1,400;1,500;1,600;1,700;1,800&family=Oswald:wght@200;300;400;500;600;700&display=swap"
    rel="stylesheet">
  <link href="style_second.css" rel="stylesheet">
</head>

<body>

  <section class="main-section">
    <div class="logo-block">
      <img src="images/logo_university.png" alt="" class="logo">
    </div>

    <div class="table-div">
      <table>

        <tr>
          <th class="table-block text">Автор</th>
          <th class="table-block text">Название</th>
          <th class="table-block text">Издание</th>
          <th class="table-block text">Жанр</th>
          <th class="table-block text">Назначение</th>
          <th class="table-block text">Редактировать</th>
          <th class="table-block text">Удалить</th>
        </tr>
        <?php for ($i = 0; $i < $startReadFilePow; $i++) :?>
        <tr>
          <td class="table-block text">
            <?php echo $all[$i][0] ?>
          </td>
          <td class="table-block text">
            <?php echo $all[$i][1] ?>
          </td>
          <td class="table-block text">
            <?php echo $all[$i][2] ?>
          </td>
          <td class="table-block text">
            <?php echo $all[$i][3] ?>
          </td>
          <td class="table-block text">
            <?php echo $all[$i][4] ?>
          </td>
          <td class="table-block text"><button onclick="" class="table-btn text">Редактировать</button></td>
          <td class="table-block text"><button onclick="" class="table-btn text">Удалить</button></td>
        </tr>
        <?php endfor; ?>
      </table>



      <button onclick="<?php header(" location:index.php "); ?>" name="submit" class="add-btn text" id="btn">Добавить</button>


    </div>
    <div class="logo-block">
      <img src="images/logo_university.png" alt="" class="logo">
    </div>

  </section>
</body>

</html>
<?php ?>

введите сюда описание изображения

5
  • 2
    php - выполняется на стороне сервера, его нельзя просто засунуть в html и ждать что произойдет чудо :) я вам вот про это место <button onclick="<?php header("location:index.php"); ?>" вместо php в этом месте нужно использовать js 11 дек 2022 в 15:18
  • дополнил кодbtn.addEventListener("click", () => { window.location.href = "list.php"; })
    – ivaivie
    11 дек 2022 в 15:35
  • но ничего не происходит, он остается на начальной странице
    – ivaivie
    11 дек 2022 в 15:35
  • Отредактируйте вопрос, измените код согласно его текущего состояния, сейчас не понятно куда и как вы вставили данный код... 11 дек 2022 в 15:36
  • Вот примерно так это должно было бы выглядеть чтоб работать: <button onclick="window.location.href = ''" name="submit" class="add-btn text" id="btn">Добавить</button> 11 дек 2022 в 15:38

1 ответ 1

1

вместо этого

<button onclick="<?php header("location:index.php"); ?>" name="submit" class="add-btn text" id="btn">Добавить</button>

ставь вот это

<button onclick="window.location.href = 'ТВОЯ ССЫЛКА';" name="submit" class="add-btn text" id="btn">Добавить</button>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.