Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将错误数组从一个php文件传递到另一个php文件,并在页面顶部显示错误?_Php_Arrays - Fatal编程技术网

如何将错误数组从一个php文件传递到另一个php文件,并在页面顶部显示错误?

如何将错误数组从一个php文件传递到另一个php文件,并在页面顶部显示错误?,php,arrays,Php,Arrays,如何将错误数组$errors从registator.php传递到registicija.php。我想在页面顶部显示所有错误registicija.php registrator.php <?php $errors = array(); $ime=trim($_POST['ime']); $strLen = mb_strlen($ime, 'utf8'); // Check stripped string if( $strLen < 1

如何将错误数组$errors从
registator.php
传递到
registicija.php
。我想在页面顶部显示所有错误
registicija.php

registrator.php

<?php
    $errors = array();

        $ime=trim($_POST['ime']);
    $strLen = mb_strlen($ime, 'utf8');
    // Check stripped string
    if( $strLen < 1 ) 
    {
    $errors[] = 'Niste uneli ime.';
    }

        $prezime=trim($_POST['prezime']);
    $strLen = mb_strlen($prezime, 'utf8');
    if( $strLen < 1 ) 
    {
    $errors[] = 'Niste uneli prezime.';
    }
?>
<form action="php/registrator.php" method="post" id="regforma" name="regforma">
<table>
  <tr>
    <td>Prezime</td>
    <td><input class="inputKontrole" name="prezime" onKeyPress="samoSlova(event, 'prezime', '40')" placeholder="prezime" type="text"></td>
  </tr>
  <tr>
    <td>Ime</td>
    <td><input class="inputKontrole" name="ime" onKeyPress="samoSlova(event, 'ime', '40')" placeholder="ime" type="text"></td>
  </tr>
  <tr>
<table>
</form>

registicija.php

<?php
    $errors = array();

        $ime=trim($_POST['ime']);
    $strLen = mb_strlen($ime, 'utf8');
    // Check stripped string
    if( $strLen < 1 ) 
    {
    $errors[] = 'Niste uneli ime.';
    }

        $prezime=trim($_POST['prezime']);
    $strLen = mb_strlen($prezime, 'utf8');
    if( $strLen < 1 ) 
    {
    $errors[] = 'Niste uneli prezime.';
    }
?>
<form action="php/registrator.php" method="post" id="regforma" name="regforma">
<table>
  <tr>
    <td>Prezime</td>
    <td><input class="inputKontrole" name="prezime" onKeyPress="samoSlova(event, 'prezime', '40')" placeholder="prezime" type="text"></td>
  </tr>
  <tr>
    <td>Ime</td>
    <td><input class="inputKontrole" name="ime" onKeyPress="samoSlova(event, 'ime', '40')" placeholder="ime" type="text"></td>
  </tr>
  <tr>
<table>
</form>

普雷齐姆
输入法

您应该使用数据库。将数据从一个php文件保存到数据库,并将数据库数据加载到另一个php文件中。在加载不同页面之间,php代码中的所有数据都会丢失

您还可以在浏览器中使用cookies。将cookies保存在一个页面中,并在另一个页面上加载

如果第二个页面在第一个页面之后加载,则可以更改链接以将要发送的数据包含在链接中。例如,
registicija.php?errors=“Niste-uneli-prezime.|Niste-uneli-ime。”
如果数组非常大,您应该使用POST请求,而不是使用javascript或表单获取