Jump to content

Recommended Posts

Hi all,

 

I have this code to display a news item. As the news item is set in the url, users can change it to whatever the want resulting in an error because that news item may not exist.

 

I'm trying to catch this error but for some reason it's not thrown. Can anyone help?

 

Here's the code:

<?php
$cntBuffer = new Databuffer();

try {
if (isset($_GET['item'])) {
	$newsId = mysql_real_escape_string($_GET['item']);
	$qryNews = "SELECT * FROM news WHERE id = $newsId";

	if (!$rsltNews = mysql_query($qryNews)) {
		Throw new Exception("error");
	}	
	$arrNews = mysql_fetch_array($rsltNews);
	echo $arrNews[1];
}
}
catch (Exception $e) {
$strError = $e->GetMessage();
echo "There is no such news item.<br /><i>$strError</i>";
}

$cntBody = $cntBuffer->close();
?>

Link to comment
https://forums.phpfreaks.com/topic/126874-solved-throwing-exceptions-not-working/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.