mrooks1984 Posted March 25, 2011 Share Posted March 25, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/231669-sqlite-php-notice-undefined-offset-0-in/ Share on other sites More sharing options...
bh Posted March 25, 2011 Share Posted March 25, 2011 Hi, Heres the problem: $arr = $results[0]; Your $result variable doesnt have a 0 index (it doesnt exists). Check it before you get. Quote Link to comment https://forums.phpfreaks.com/topic/231669-sqlite-php-notice-undefined-offset-0-in/#findComment-1192079 Share on other sites More sharing options...
mrooks1984 Posted March 25, 2011 Author Share Posted March 25, 2011 thanks for you reply i am a newbie learning or tring to learn php, what do you mean by check it? i have tried removing the 0 as i knew it was something to do with that part but it dident work. Quote Link to comment https://forums.phpfreaks.com/topic/231669-sqlite-php-notice-undefined-offset-0-in/#findComment-1192081 Share on other sites More sharing options...
monkeytooth Posted March 25, 2011 Share Posted March 25, 2011 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" Quote Link to comment https://forums.phpfreaks.com/topic/231669-sqlite-php-notice-undefined-offset-0-in/#findComment-1192094 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.