Reputation: 878
I have the following PHP code:
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'];
The condition in the if statment (if(!$article_ID)
) should try to get the value in get method, and if it can't so it will throw exception and pass to the catch
part, it works fine, but I see error message in my webpage any time it comes to the catch (Notice: Undefined index: articleID on line 6
) why? and how can I hide this message?
Upvotes: 0
Views: 157
Reputation: 4446
Notices do not throw exceptions. The notice is in the first line, because there is no "ArticleID" key in $_GET array variable.
I think you could do something like this
$articleID = isset($_GET["articleID"]) ? $_GET["articleID"] : '';
Upvotes: 1