我在深度预订系统上工作,我坚持使用标题功能而不是将用户重定向到' index.php'页。这是我的PHP代码。
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM customer WHERE transactionum = '$ticket' ";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "<strong>".$row["fname"]. " " . $row["lname"]."</strong><br>";
}
} else {
header('location:index.php');
}
?></li>
<li class="list-group-item">Paid: <?php if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM customer WHERE transactionum = '$ticket' ";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "<strong>".$row["paid"]. "</strong><br>";
}
} else {
header('location:index.php');
}
答案 0 :(得分:-1)
//创建连接
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM customer WHERE transactionum = '$ticket' ";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$test1 = "<strong>".$row["fname"]. " " . $row["lname"]."</strong><br>";
}
} else {
header('location:index.php');
}
?></li>
<li class="list-group-item">Paid: <?php if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM customer WHERE transactionum = '$ticket' ";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$var1 = "<strong>".$row["paid"]. "</strong><br>";
}
} else {
header('location:index.php');
}
echo $test1;
echo $var1;
答案 1 :(得分:-1)
查看此网址http://php.net/manual/es/function.header.php 使用大写字母
header('Location: http://www.example.com/');
尝试使用此表单并确保代码“else”执行。