对于下面的代码,我通过使用href方法从另一个页面按传递了4个参数。这样,在这段代码中,我使用GET方法接收所有这4个值,并在不同的值下回显它们。但是,当我想通过按标题返回到index.php时,它不会将我定向到该页面。即使它应该引导我的正确链接是index.php,也会将我引导到bookingdays.php / index.php。请帮助我,谢谢!
<?php
if($_GET != NULL){
$price = $_GET['price'];
$duration= $_GET['duration'];
$car = $_GET['car'];
$imgLink=$_GET['image'];
}
else{
header("location:index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="img/CarRent.ico" >
<title>Booking | Kereta Sewa Bajet</title>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-
awesome/4.7.0/css/font-awesome.min.css">
<style>
.booking-box{
width: 400px;
border: 2px solid #2c3e50;;
padding: 10px;
margin: 5% auto 0;
border-radius:10px;
}
input[type="number"]{
width: 160px;
height: 30px;
}
input[type="date"]{
width: 160px;
height: 30px;
}
input[type="submit"]{
width: 320px;
height: 30px;
}
.btn-green{
border-radius:10px;
color: white;
background-color: #27ae60;
}
.btn-red{
border-radius:10px;
color: white;
background-color: red;
}
body, html {
height: 100%;
line-height: 1.8;
}
.w3-bar .w3-button {
padding: 16px;
}
input[type="text"]{
width: 160px;
height: 30px;
}
</style>
</head>
<body>
<!-- Navbar (sit on top) -->
<div class="w3-top">
<div class="w3-bar w3-white w3-card" id="myNavbar">
<a href="index.php" class="w3-bar-item w3-button w3-wide">KERETA SEWA BAJET</a>
<!-- Right-sided navbar links -->
<div class="w3-right w3-hide-small">
<a href="login.php" class="w3-bar-item w3-button"><i class="fa fa-user"></i>
LOGIN</a>
<a href="menu.php" class="w3-bar-item w3-button"><img src="img/MYR.png"
style="width:25px;height:25px;"> PACKAGE PRICES</a>
<a href="#contact" class="w3-bar-item w3-button"><i class="fa fa-envelope"></i>
CONTACT</a>
<a href="aboutus.php" class="w3-bar-item w3-button">ABOUT US</a>
</div>
<!-- Hide right-floated links on small screens and replace them with a menu icon -->
<a href="javascript:void(0)" class="w3-bar-item w3-button w3-right w3-hide-large w3-
hide-medium" onclick="w3_open()">
<i class="fa fa-bars"></i>
</a>
</div>
</div>
<!-- Sidebar on small screens when clicking the menu icon -->
<nav class="w3-sidebar w3-bar-block w3-black w3-card w3-animate-left w3-hide-medium w3-
hide-
large" style="display:none" id="mySidebar">
<a href="javascript:void(0)" onclick="w3_close()" class="w3-bar-item w3-button w3-large
w3-padding-16">Close ×</a>
<a href="#login" onclick="w3_close()" class="w3-bar-item w3-button">LOGIN</a>
<a href="menu.php" onclick="w3_close()" class="w3-bar-item w3-button">PACKAGE PRICES</a>
<a href="#contact" onclick="w3_close()" class="w3-bar-item w3-button">CONTACT</a>
<a href="aboutus.php" onclick="w3_close()" class="w3-bar-item w3-button">ABOUT US</a>
</nav>
<script>
// Toggle between showing and hiding the sidebar when clicking the menu icon
var mySidebar = document.getElementById("mySidebar");
function w3_open() {
if (mySidebar.style.display === 'block') {
mySidebar.style.display = 'none';
} else {
mySidebar.style.display = 'block';
}
}
// Close the sidebar with the close button
function w3_close() {
mySidebar.style.display = "none";
}
</script>
<header class="bgimg-1 w3-display-container w3-grayscale-min" style="padding:48px"
id="home">
<div class="booking-box">
<form action="#" method="#">
<center><b>My Booking Details</b></center>
<br>
<center><img style="width:220px; height:140px" src="<?php echo $imgLink ?>"></center>
<br>
<table>
<tr>
<th>Car</th>
<td>:</td>
<td><input type="text" name="car" value="<?php echo $car?>" id="car" readonly >
</td>
</tr>
<tr>
<th>Duration (Day)</th>
<td>:</td>
<td><input type="text" name="duration" value=" <?php echo $duration ?>" id="duration"
readonly ></td>
</tr>
<tr>
<th></br>Date Range</th>
<td></td>
<td><br><b></b></td>
</tr>
<tr>
<th>From</th>
<td>:</td>
<td><input type="date" id="dateFrom" min="<?php echo date ("Y-m-d",
time()+129600) ?>" onchange="calculateDate()" required></td>
</tr>
<tr>
<th>To</th>
<td>:</td>
<td><input type="text" id="dateTo" onchange="calculateDate()" style= "width:
160px; height: 30px;" readonly></td>
</tr>
<tr>
<th>Total Price</th>
<td><br>:<br><br></td>
<td><strong><input type="text" border="none" name="price" value=" <?php echo
$price ?>" id="cuba" readonly ></strong></td>
</tr>
</table>
<center>
<input class="btn-green" type="submit" value=" BOOK "><br>
<input class="btn-red" type="submit" value=" CANCEL ">
</center>
</div>
</form>
</header>
<script>
function calculateDate() {
var date_from = document.getElementById('dateFrom').value;
var new_date = new Date(date_from);
var date_to = new Date(new_date);
var day = document.getElementById('duration').value;
if(day==1){
date_to.setDate(date_to.getDate());
}
else if(day==3){
date_to.setDate(date_to.getDate()+2);
}
else{
date_to.setDate(date_to.getDate()+6);
}
var dd = date_to.getDate();
var mm = date_to.getMonth() +1 ;
var yy = date_to.getFullYear();
if(mm==1)
mm = "Jan";
else if(mm==2)
mm = "Feb";
else if(mm==3)
mm = "Mar";
else if(mm==4)
mm = "Apr";
else if(mm==5)
mm = "May";
else if(mm==6)
mm = "Jun";
else if(mm==7)
mm = "Jul";
else if(mm==8)
mm = "Aug";
else if(mm==9)
mm = "Sep";
else if(mm==10)
mm = "Oct";
else if(mm==11)
mm = "Nov";
else
mm = "Dec";
var someFormattedDate = '' + dd + '-' + mm + '-' + yy;
document.getElementById('dateTo').value = someFormattedDate;
}
</script>
<br>
<footer class="w3-center w3-black w3-padding-32">
<img src="img/BudgetLOGO.PNG" alt=""style="width:85px;height:25px;>
<br clear="all" />
<p>Owned by KSB</p>
<img src="img/BudgetLOGO.PNG" alt=""style="width:80px;height:35px;>
</footer>
</body>
</html>
答案 0 :(得分:0)
您可以尝试使用location:../index.php
或location:/index.php
。前者将您带到index.php
的目录,后者将您带到顶层目录,然后index.php