我正在寻找一种方法来保持表单值在同一代码中的不同提交之后。
要在首次提交后保留文字,我使用了:
value="<?php echo isset($_POST['Modellocerca']) ? $_POST['Modellocerca'] : '' ?>" name="Modellocerca"
然而,在第二次提交'Cerca'之后,我丢失了表格中的文字。 我真的很想,但我需要你的帮助。
<html>
<link href="Stile/TMO.css" rel="stylesheet" type="text/css" />
<header>
<!-- MENU NOT RELEVANT -->
<ul>
<li><a href="Benvenuto.php">Home</a></li>
<li class="sottomenu">
<a href="javascript:void(0)" class="dropbtn">Importa</a>
<div class="sottomenu-content">
<a href="Importa.php">Sk. Reali</a>
</div>
</li>
<li><a href="">Esporta</a></li>
<li id="Logout"> <a href="Logout.php"> Logout</a> </li>
</ul>
</header>
<body>
<!-- FIRST FORM WITH FIRST SUBMIT BUTTON -->
<h3>Motore di ricerca</h3>
<form action="" method="POST" >
Modello: <input type="text" value="<?php echo isset($_POST['Modellocerca']) ? $_POST['Modellocerca'] : '' ?>" name="Modellocerca" />
<input type="submit" value="Cerca" Name="Cerca" /> <!-- First problem -->
</form>
<!-- PHP RELATED TO FIRST SUBMIT -->
<?php
include('session.php');
if(isset($_POST['Cerca']))
{
$Modellocerca="%";
if ($_POST['Modellocerca'] != null) {$Modellocerca = $_POST['Modellocerca'];};
$sql=("SELECT DISTINCT `MODELLO`, `ODM` FROM `DBMB`.`TMO` WHERE `MODELLO` LIKE '%" . $Modellocerca . "%'");
$sql_cerca = $db->prepare($sql);
$sql_cerca->execute();
$auxmod="start";
foreach($db->query($sql) as $row)
{
if($auxmod!=$row['MODELLO'] || $auxmod=="start") {
$Combomod = $Combomod . ('<option>' . $row['MODELLO'] . '</option>');
$auxmod=$row['MODELLO'];};
};
$sqlcerca=null;
};
?>
// PLOT INTO SELECT BOX THE SEARCH RESULTS AND SECOND SUBMIT FOR LOAD DATA AFTER SELECT THE RESULT
<form action="" method="POST" >
<h3>Odm Filtrati</h3>
<!-- Modello -->
Modello: <select name="Modellocombo">
<?php
var_dump ($Combomod);
?> </select>
<input type="submit" name="Carica" value="Carica" > <!-- Second problem -->
</form>
答案 0 :(得分:0)
您可以使用$ _SESSION变量来获取上一个表单的输入。