我想向我正在使用的此php代码添加一个后退按钮。因此,一旦输入详细信息并单击“注册”,我就会得到“成功插入新记录”。
这很棒,但是我想添加一个后退按钮,可以将我带回到另一页。
下面是我的代码。我也不知道在哪里放置后退按钮
<?php
$FirstName = filter_input(INPUT_POST, 'FirstName');
$LastName = filter_input(INPUT_POST, 'LastName');
$username = filter_input(INPUT_POST, 'username');
$Email = filter_input(INPUT_POST, 'email');
$password = filter_input(INPUT_POST, 'password');
if (!empty($username)){
if (!empty($password)){
$host = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "test";
// Create connection
$conn = new mysqli ($host, $dbusername, $dbpassword, $dbname);
if (mysqli_connect_error()){
die('Connect Error ('. mysqli_connect_errno() .') '
. mysqli_connect_error());
}
else{
$sql = "INSERT INTO details (Username, Password, FirstName, LastName, Email)
values ('$username','$password','$FirstName','$LastName','$Email')";
if ($conn->query($sql)){
echo "New record is inserted sucessfully";
}
else{
echo "Error: ". $sql ."
". $conn->error;
}
$conn->close();
}
}
else{
echo "Password should not be empty";
die();
}
}
else{
echo "Username should not be empty";
die();
}
?>
答案 0 :(得分:1)
if ($conn->query($sql)){
echo "New record is inserted sucessfully";
echo '<button onclick="history.go(-1);">Back </button>';
}
OR
echo '<a href="' . echo $_SERVER['HTTP_REFERER'] . '">Back</a>';