404 if record not found - 如何检查记录是否存在?
我认为我在上一个问题中没有充分解释自己。
我有一个页面显示各种元素,即使它从数据库调用的 id 不存在或已被删除(这会引发各种丑陋的错误,并且搜索引擎继续列出不存在的页面)。
如果 $id 不存在,您是否可以修改下面显示的页面代码的第一部分以发送 404(或至少发送到具有 404 标头的 projecterror.php)?非常感谢!
<?php
include_once("includes/linkmysql.php");
$adda=$_GET['a'];
$cont=$_GET['c'];
$select="SELECT * FROM projects where id='$id'";
$qselect = mysql_query($select);
while ($row = mysql_fetch_array($qselect)) {
I don't think I explained myself adequately in my previous question.
I have a page that displays various elements even if the id it's calling from the database does not exist or was deleted (which throws up all sorts of ugly errors along with search engines continuing to list non-existent pages).
Can you modify the first part of the page code shown below to send a 404 (or at least to projecterror.php which has 404 headers) if $id does not exist? Many thanks!
<?php
include_once("includes/linkmysql.php");
$adda=$_GET['a'];
$cont=$_GET['c'];
$select="SELECT * FROM projects where id='$id'";
$qselect = mysql_query($select);
while ($row = mysql_fetch_array($qselect)) {
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
由于仅依赖 HTTP 错误代码有时可能有点过于模糊,因此我建议您除了常规 HTTP 状态代码之外,还将该错误包含在 XML/JSON 响应消息中。
这样您就可以提供更好的日志记录,并且由于错误在消息中详细说明,因此它将大大缩短调试时间/为您提供更清楚地呈现错误来源的机会。
Since only relying on HTTP error codes sometimes can be a little too ambiguous, I suggest you include the error in an XML/JSON response message in addition to the general HTTP status code.
That way you can provide better logging and since the error is stated in detail in the message it will drastically shorten debugging time / provide the opportunity for you to present the source of the error more clearly.
这些是@Vivek Goel 在您提出的其他问题上为您提供的标题代码
These are the header codes @Vivek Goel gave you on the other questions you asked
上面的答案中没有人在 MySQLI 中回答它,如果在数据库中找不到记录,则 Mysqli 使用以下
代码
www.psychocodes.in
No one in the above answers have answered it in MySQLI for Mysqli use the below code if a record is not found in the database
regards
www.psychocodes.in