gpt4 book ai didi

php - 从搜索 php 脚本创建错误页面

转载 作者:行者123 更新时间:2023-11-29 08:54:29 25 4
gpt4 key购买 nike

如果出现错误,是否可以更改我的搜索脚本以将客户端定向到不同的页面?

我希望将它们定向到 search_error1.php,而不是显示文本“未找到结果!”。

我希望将它们定向到 search_error2.php,而不是显示文本“您尚未输入搜索字段”。

<?php

$error = '';

if (isset($_POST['Submit'])) {
if (!empty($_POST['reg'])) {

$record = $_POST['reg'];

$query = mysql_query("SELECT * FROM reg_add WHERE reg='" . mysql_real_escape_string($record) . "'");
$result = mysql_num_rows($query);

if ($result != 0) {

$row = mysql_fetch_array($query);

$first_name = $row['first_name'];
$last_name = $row['last_name'];
$reg = $row['reg'];

} else {$error = 'No result have been found!';}

} else {$error = 'You have not entered the search field, <a href="javascript:history.back(1)">Go back</a>.';}

}

if (!empty($error)) { echo $error; }

?>

最佳答案

是的

使用header()

http://se2.php.net/manual/en/function.header.php

} else { header("Location: search_error1.php"); exit; }

} else { header("Location: search_error2.php"); exit; }

您的代码(+预期)将如下所示:

<?php
if (isset($_POST['Submit'])) {
if (!empty($_POST['reg'])) {

$record = $_POST['reg'];

$query = mysql_query("SELECT * FROM reg_add WHERE reg='" . mysql_real_escape_string($record) . "'");
$result = mysql_num_rows($query);

if ($result != 0) {

$row = mysql_fetch_array($query);

$first_name = $row['first_name'];
$last_name = $row['last_name'];
$reg = $row['reg'];

} else {
header("Location: search_error1.php");
exit;
}

} else {
header("Location: search_error2.php");
exit;
}
}
?>

关于php - 从搜索 php 脚本创建错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10337579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com