如何将错误数组从一个php文件传递到另一个php文件,并在页面顶部显示错误?
如何将错误数组$errors从如何将错误数组从一个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
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或表单获取