我在推送提交后将文本保留在先前存在的文本字段中时遇到问题。我正在使用这个:
<input name="date" type="text" id="date" <?php if(isset($_POST['date'])){echo 'value="'.$_POST['date'].'"';} ?>/>
我在成功提交时也有这个,以便它重新加载表格但也删除上面的内容,因为它令人耳目一新。
echo "Succesfully added transaction. Updating table...";
echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"6\">";
我的整个代码=
<?php
// if ('POST' === $_SERVER['REQUEST_METHOD'])
if (isset($_POST['submit2']))
{
$con = mysql_connect("xx","xx_xx","xx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("xx_xx", $con);
$date = $_POST['date'];
$_SESSION['date'] = $_POST;
//Writes the to the server
$sql = mysql_query("INSERT INTO `reservation__date` (`reservation_id`, `reservation_date`)
VALUES
('000', '$date')") or die(mysql_error());
$query = mysql_query($sql);
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
$_SESSION['DATE'] = $_REQUEST['date'];
echo "Succesfully added transaction. Updating table...";
echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"6\">";
mysql_close($con);
}
}
?>