다음 PHP 코드가 있습니다.
try{
$article_ID =$_GET["articleID"];
if(!$article_ID) {
throw new Exception("Invalid query: ". mysql_error());
}
else {
$select_query = mysql_query("SELECT articleContent, articleTitle From articles WHERE articleID=$article_ID AND typeID=$type_ID");
}
}
catch(Exception $e) {
//echo $e->getMessage();
$select_query = mysql_query("SELECT articleContent, articleTitle From articles WHERE typeID=$type_ID");
}
$row = mysql_fetch_assoc($select_query);
echo '<h1>'.$row['articleTitle'].'</h1>';
echo $row['articleContent'];
if 문 ( if(!$article_ID)
) 의 조건은 get 메서드에서 값을 가져 오려고 시도해야하며, 그렇지 않으면 예외를 throw하고 해당 catch
부분에 전달하면 정상적으로 작동하지만 웹 페이지에 언제든지 오류 메시지가 표시됩니다. 캐치에 온다 ( Notice: Undefined index: articleID on line 6
) 왜? 이 메시지를 어떻게 숨길 수 있습니까?
통지는 예외를 발생시키지 않습니다. $ _GET 배열 변수에 "ArticleID"키가 없기 때문에 알림이 첫 번째 줄에 있습니다.
이런 식으로 할 수있을 것 같아요
$articleID = isset($_GET["articleID"]) ? $_GET["articleID"] : '';
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다