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
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"

Link to comment
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.