[英]Create error pages from search php script
如果出现错误,是否可以更改我的搜索脚本以将客户端定向到其他页面?
而不是让文本显示“没有找到结果!”,我希望将它们定向到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;
}
}
?>
而不是echo
错误,使用标头重定向。 例。
header("Location: search_error1.php");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.