Php 将表单数据插入数据库后,如何清除表单数据
提交数据并将其插入数据库后,如何清除表单数据?因此,用户无法在提交数据后按back和refresh重新输入数据,因为此时他们可以。另外,请忽略MYSQL根登录,这只是出于测试目的 这是我的密码Php 将表单数据插入数据库后,如何清除表单数据,php,mysql,html,forms,mysqli,Php,Mysql,Html,Forms,Mysqli,提交数据并将其插入数据库后,如何清除表单数据?因此,用户无法在提交数据后按back和refresh重新输入数据,因为此时他们可以。另外,请忽略MYSQL根登录,这只是出于测试目的 这是我的密码 <?php session_start(); if (isset($_POST['sub'])) { $host='localhost'; $user='root'; $pass=''; $db='theatre_booking'; $con=mysqli_connect($host,$user
<?php
session_start();
if (isset($_POST['sub'])) {
$host='localhost';
$user='root';
$pass='';
$db='theatre_booking';
$con=mysqli_connect($host,$user,$pass,$db);
$row = $_POST['row'];
$_SESSION["row"]=$row;
$zone = $_POST['zone'];
$_SESSION["zone"]=$zone;
$quantity = $_POST['qty'];
$_SESSION["qty"]=$quantity;
$quantity = $_POST['quotation'];
$_SESSION["quotation"]=$quantity;
$sql="INSERT INTO booking(PerfDate, PerfTime, Name, Email, RowNumber)
VALUES (
'{$_SESSION['date']}',
'{$_SESSION['time']}',
'{$_SESSION['name']}',
'{$_SESSION['email']}',
'{$_SESSION['row']}')";
if ($con->query($sql) === TRUE) {
echo "Booking successful";
} else {
echo "Error: " . $sql . "<br>" . $con->error;
}
}
?>
<!------------------------------------------------------------------------------------>
<DOCTYPE! html>
<html>
<head>
<meta charset="uft-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"">
<meta name= "viewport" content="width=device-width, initial-scale=1.0">
<link href="style/styles.css" type="text/css" rel="stylesheet">
</head>
<body>
<h2 id="siteTitle">Westend</h2>
<nav>
<ul class="main_menu">
<li><a href="index.php">Home</a></li>
<li><a href="booking.php" >Booking</a></li>
</ul>
</nav>
<!--Image shown in the background after booking is confirmed-->
<div><img src="images/curtains.jpg" id="open"/>
<!--Booking confirmation message the user sees-->
<div id="process">
</br>Hi <?php echo "'".$_SESSION['name']."'"; ?></br>
Your tickets have been booked for <?php echo "'".$_SESSION['production']."'";?>
</br>Playing on <?php echo "'".$_SESSION['date']."'";?> at <?php echo "'".$_SESSION['time']."'";?> </br>
You are in <?php echo $_POST["zone"];?> in row <?php echo $_POST["row"];?></br>
The total cost is £<?php echo $_POST["quotation"];?></br>
Confirmation of your booking has been sent to: <?php echo "'".$_SESSION['email']."'"; ?></br>
</br>
Enjoy the show!
</br>
</div>
</div>
<!--Footer-->
<footer>
<p class="pageBottom">© Westend 2015</p>
</footer>
</body>
</html>
我在这里回答,这样我可以添加一些代码吗
if(isset($_POST["row"] && !empty($_POST["row"]){
$sql="INSERT INTO booking(PerfDate, PerfTime, Name, Email, RowNumber)
VALUES (
'{$_SESSION['date']}',
'{$_SESSION['time']}',
'{$_SESSION['name']}',
'{$_SESSION['email']}',
'{$_SESSION['row']}')";
if ($con->query($sql) === TRUE) {
echo "Booking successful";
} else {
echo "Error: " . $sql . "<br>" . $con->error;
}
}
if(设置($\u POST[“行”]&&!空($\u POST[“行”])){
$sql=“插入预订(PerfDate、PerfTime、姓名、电子邮件、行号)
价值观(
“{$\u会话['date']}”,
“{$\u会话['time']}”,
“{$\u会话['name']}”,
“{$\u会话['email']}”,
“{$_SESSION['row']}”)”;
如果($con->query($sql)==TRUE){
回音“预订成功”;
}否则{
echo“Error:”.$sql.“
”$con->Error;
}
}
为什么要将此值放入$\u会话中?使用简单的变量,您就会解决问题。另外,我建议您在$\u POST变量中执行一些控件,以避免sql注入攻击@Alessandro.Vegna$\u会话包含从表单的前几页收集的值,因此已结转。我如何将控件添加到$\u POST va变量?对于控件,请看这里。好的,那么您可以在$sql=…之后添加一个if-like-if(isset($\u-POST[“row”]&&!empty($\u-POST[“row”])。另一个建议是使用更具可读性的use。我认为您必须在php.iniThanks@alesandro.Vegna中激活短的\u-open标记