データベースから呼び出されたIDが存在しない、または削除されていても、さまざまな要素を表示するページがあります(すべての種類の醜いエラーをスローします存在しないページをリストする)。PHPページのリダイレクトの問題 - ヘッダー情報を変更できない
$ 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)) {
など親切に Vivek Goel正しくページを示す有効なエントリで結果が、存在しないページこの修正されたコードの下にエラー表示されていることにより、元のコメントの結果としてMatt Wilsonによって提案された以下の修正:
を上記の修飾から生じる<?php
include_once("includes/linkmysql.php");
$adda=$_GET['a'];
$cont=$_GET['c'];
$select="SELECT * FROM projects where id='$id'";
$qselect = mysql_query($select);
if(mysql_num_rows($qselect) === 0)
{
header("HTTP/1.1 301 Moved Permanently");
header('Location: http://examplesite.domain/errorpage') ;
exit;
}
while ($row = mysql_fetch_array($qselect)) {
エラー:
Warning: Cannot modify header information - headers already sent by (output started at /home/website/public_html/header1.php:14) in /home/website/public_html/header1.php on line 22
Warning: Cannot modify header information - headers already sent by (output started at /home/website/public_html/header1.php:14) in /home/website/public_html/header1.php on line 23 Lines 22 and 23 are the two header lines in your example above
線22 nd 23は、次の2つのヘッダー行です。
header("HTTP/1.1 301 Moved Permanently");
header('Location: http://examplesite.domain/errorpage') ;
偉大な仕事 - これはまさに期待通りに働いて、多くの感謝! – JoeW
完璧に働いた!ありがとう! –
すばらしい解決策! – Newbyman