Jump to content

sqlite php Notice: Undefined offset: 0 in


mrooks1984

Recommended Posts

hello all, i am stuck with a problem and hoping someone can help me.

i have got the following code to sort of work.

the problem i am having is when i put e.g. index.php?page=test and there is no information with test under page in the sqlite db i get this message, Notice: Undefined offset: 0 in C:\xampp\htdocs\test\Frontend\left.php on line 8.

as soon as i type index.php?page=test2 and i have test2 in the database the error is gone and shows the content

heres the code


        if (isset($_GET['page']))
        {
	$page = $_GET['page'];

	// Display Page.
	$query = "SELECT body FROM content WHERE page = '$page' AND location = 'left' AND disabled = 'no' ORDER BY id";
	$results = $base->arrayQuery($query, SQLITE_ASSOC);
	$arr = $results[0];

			echo '<div id="left">';		
                echo '<p>' . $arr['body'] . '</p>';
			echo '</div>';

	}		
        else
        {
                //Show Home Page
	$query = "SELECT body FROM content WHERE page = 'home' AND location = 'left' AND disabled = 'no' ORDER BY id";
	$results = $base->arrayQuery($query, SQLITE_ASSOC);
	$arr = $results[0];

			echo '<div id="left">';
                echo '<p>' . $arr['body'] . '</p>';
			echo '</div>';    
                
}

hope you understand what i am trying to say, thanks very much all.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/231669-sqlite-php-notice-undefined-offset-0-in/
Share on other sites

Do a count query.. if the count is 0 then show something else by default. If its 1 (assuming the variable your using would be a unique one) then show the information for that variable. Also since your using _GET/_POST type variables, I would suggest reading up on "Sanitizing your queries" and "mySQL injection prevention"

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.