Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· openaiHugging Face Suzhen/CodeChat

Есть файл Galvene.php <?php // Example 27-2: header.php sessionstart(); echo <<<INIT…

  1. User

    Есть файл Galvene.php

      </div>
      <div id="table2" class="table-container">
          <?php include 'table_2.php'; ?>
      </div>
      <div id="text-container">
          <p>Izveleties datu bazi augšeja saites daļa</p>
      </div>
    

    Есть файл functions.php

  2. Assistant

    Код содержит ошибки и не может быть выполнен. Например, в функции showTable отсутствует ключевое слово function, в функции show используются операторы PHP в рамках JavaScript, и т.д. Для корректного исполнения кода необходимо исправить ошибки и установить соответствующие значения переменным и запросам.

  3. User

    Можешь это сделать?

  4. Assistant

    Конечно, вот исправленный код:

    Galvene.php:

    <?php // Example 27-2: header.php
    session_start();
    
    echo <<<_INIT
    <!DOCTYPE html> 
    <html>
      <head>
        <meta charset='utf-8'>
        <meta name='viewport' content='width=device-width, initial-scale=1'> 
        <link rel='stylesheet' href='jquery.mobile-1.4.5.min.css'>
        <link rel='stylesheet' href='styles.css' type='text/css'>
        <script src='javascript.js'></script>
        <script src='jquery-2.2.4.min.js'></script>
        <script src='jquery.mobile-1.4.5.min.js'></script>
        <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=Manrope&display=swap" rel="stylesheet">
        <title>Uzskaite</title>
      </head>
      <body>
    
      <a href="https://rezeknestehnikums.lv/" id="logo-header"></a>
    
    _INIT;
    
    require_once 'functions.php';
    
    $userstr = 'Viesis';
    
    if (isset($_SESSION['user'])) {
      $user     = $_SESSION['user'];
      $loggedin = true;
    } else {
      $loggedin = false;
    }
    
    if ($loggedin) {
      echo <<<_LOGGEDIN
      <button id="Dezures" onclick="showTable('table1'); hideTextContainer();">Dežurēs</button>
      <button id="Audzeknu-Uzskaite" onclick="showTable('table2'); hideTextContainer();">Audzēkņu uzskaite</button>
      <div id="ZilsUzskaitesFons"></div>
      <div id="FonaTekstura"></div>
      <div id="ZalsTabulasFons"></div>
      <div id="TabulasZona">
          <div id="table1" class="table-container">
              <?php include 'table_1.php'; ?>
          </div>
          <div id="table2" class="table-container">
              <?php include 'table_2.php'; ?>
          </div>
          <div id="text-container">
              <p>Izvelēties datu bazi augšeja saites daļā</p>
          </div>
      </div>
      <button id="PogaPievienosana" onclick="openModal()">Pievienot</button>
      <div id="modal" class="modal"></div>
      <a href="ielogoties.php" id="PogaIziet">Iziet</a>
      <button id="TekstaPogaMeklet">
          <div id="search"></div>Meklēt
      </button>
      <button id="TekstaPogaMainit">Mainīt</button>
      <div id="TabulasVirsraksts">Datu baze</div>
    _LOGGEDIN;
    } else {
      echo <<<_GUEST
      <div id="ZalsFons"></div>
      <div id="FonaTekstura"></div>
      <button id="SadalaPieteiktiesPiekluvejs" onclick="show('LoginForm'); hideTextContainer();">Pieteikties piekļuvei</button>
      <button id="SadalaIelogoties" onclick="show('RegisterForm'); hideTextContainer();">Ielogoties</button>
      <div id="LoginForm" class="table-container">
          <?php include 'Ielogoties.php'; ?>
      </div>
      <div id="RegisterForm" class="table-container">
          <?php include 'PieteiksanasPiekluvej.php'; ?>
      </div>
    _GUEST;
    }
    
    echo <<<_MAIN
        <script>
          function showTable(tableId) {
            var tables = document.getElementsByClassName('table-container');
            for (var i = 0; i < tables.length; i++) {
              tables[i].style.display = 'none';
            }
            document.getElementById(tableId).style.display = 'block';
          }
    
          function hideTextContainer() {
            var textContainer = document.getElementById('text-container');
            textContainer.style.display = 'none';
          }
    
          function openModal() {
            var modal = document.getElementById('modal');
            modal.style.display = 'block';
          }
    
          function show(formId) {
            document.getElementById('RegisterForm').style.display = 'none';
            document.getElementById('LoginForm').style.display = 'none';
            document.getElementById(formId).style.display = 'block';
            hideTextContainer(); // Optionally hide the text container
          }
    
          function closeModal() {
            var modal = document.getElementById('modal');
            modal.style.display = 'none';
          }
        </script>
    _MAIN;
    
    ?>
    

    functions.php:

    <?php // Example 27-1: functions.php
    $dbhost  = 'localhost';    // Your database server host
    $dbname  = 'your_database_name';   // Your database name
    $dbuser  = 'your_database_username';   // Your database username
    $dbpass  = 'your_database_password';   // Your database password
    
    $connection = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
    if ($connection->connect_error) die("Fatal error");
    echo "<br>";
    
    function createTable($name, $query) {
      global $connection;
      queryMysql("CREATE TABLE IF NOT EXISTS $name($query)");
      echo "Table '$name' created or already exists.<br>";
    }
    
    function queryMysql($query) {
      global $connection;
      $result = $connection->query($query);
      if (!$result) die("Fatal error");
      return $result;
    }
    
    function destroySession() {
      $_SESSION = array();
    
      if (session_id() != '' || isset($_COOKIE[session_name()])) setcookie(session_name(), '', time()-2592000, '/');
    
      session_destroy();
    }
    
    function sanitizeString($var) {
      global $connection;
      $var = strip_tags($var);
      $var = htmlentities($var);
      if (get_magic_quotes_gpc()) $var = stripslashes($var);
      return $connection->real_escape_string($var);
    }
    
    function showProfile($user) {
      if (file_exists("$user.jpg")) echo "<img src='$user.jpg' style='float:left;'>";
    
      $result = queryMysql("SELECT * FROM profiles WHERE user='$user'");
    
      if ($result->num_rows) {
        $row = $result->fetch_array(MYSQLI_ASSOC);
        echo stripslashes($row['text']) . "<br style='clear:left;'><br>";
      } else {
        echo "<p>No profile data available.</p><br>";
      }
    }
    
    // Take information from table
    $sqltable1 = "SELECT * FROM dezures";
    $sqltable2 = "SELECT * FROM audzeknu_uzskaite";
    $result1 = $connection->query($sqltable1);
    $result2 = $connection->query($sqltable2);
    $table = '-';
    
    ?>
    

    Пожалуйста, убедитесь, что переменные dbname, dbuser и dbpass установлены правильно для вашей базы данных.