0

At this moment i access my posts like this

http://localhost/post/174565/

and everything works fine, but when i am trying to access them like this

http://localhost/post/1745s65/

i am getting error

Error Number: 1054
Unknown column '1745s65' in 'where clause'
SELECT * FROM posts WHERE id = 1745s65;
Filename: D:\Localhost\Apache\htdocs\code\system\database\DB_driver.php
Line Number: 330

i understand why it is there, but how to handle it? For example my users don't need to see SQL query, and i want to show them 404 page instead of this block.

4
  • post your code that queries the db based on the url. Commented Mar 30, 2013 at 23:19
  • for what you need it? post is not about debuging sql query, but handling errors :) Commented Mar 30, 2013 at 23:42
  • 1
    to see the way that you parse the query. Normally, if you used active record correctly you should not see the above error. Commented Mar 30, 2013 at 23:43
  • Ahh, ok, here it is pastebin.com/aPt7VYuJ Commented Mar 30, 2013 at 23:45

3 Answers 3

2

use execptions:

try{
       //here what you need to do with script
         } catch (Exception $e) {
            var_dump($e->getMessage());
            show_404();
              }

i think you can try also to put :

$database['db_debug'] = FALSE; in config/database.php if you want to remove database errors from being shown

Sign up to request clarification or add additional context in comments.

Comments

1

Try this code:

public function getPostData($iPostId) {
    $sqlQuery = $this->db->get_where('posts', array('id' => $iPostId));
    $aResult = $sqlQuery->result();

    if (empty($aResult)) {
        show_404();
    }
    else {
        return $aResult[0];
    }
}

1 Comment

Magic method! Works just perfectly.
0

You need to validate user input to prevent this issues. Anyhow, Codeigniter has two preset environments: development and prodution. Check your root index.php for more information.

1 Comment

I thought about checking is_numeric and if SQL result !empty, thought there are some built-in functions :) Production environment changes nothing in this situation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.