CodeIgniter Forums
whats wrong with this? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: whats wrong with this? (/thread-26289.html)



whats wrong with this? - El Forum - 01-10-2010

[eluser]dadamssg[/eluser]
Ok so im checking a segment of the uri to make sure its set and numeric and then if it is see if i can find the id number in my db, if not redirect. When i enter an id number thats in the db it works, if its a number thats not in the db it redirects...ok good. BUT if i enter in something like "adsg324" i get a 404 and its not redirecting. whats the deal here?
Code:
if (isset($id) && is_numeric($id))
        {
              $yes = $this->Eventmodel->get_exists($id);
              if($yes !== 1){redirect('mains');}
            }
            else
            {
              redirect('mains');
            }



whats wrong with this? - El Forum - 01-10-2010

[eluser]Udi[/eluser]
Is there any $route[..] for this part of code?
maybe you added (:num) to the url ($route['some/controller/(:num)'] )


whats wrong with this? - El Forum - 01-10-2010

[eluser]dadamssg[/eluser]
yeah heres the route

$route['events/(:num)'] = 'events/index/$1';

i just don't want sql injections from my segments


whats wrong with this? - El Forum - 01-10-2010

[eluser]Udi[/eluser]
The segment didn't passed CI's check, it supposed to be numeric. Consider it that CI already made the is_numeric() check for you - and because its not numeric, you're thrown to 404.

If you want to handle it yourself, change it to (:any) - this way your code will work as you wanted.


whats wrong with this? - El Forum - 01-10-2010

[eluser]Craig A Rodway[/eluser]
The route only works for numeric values (the :num part). If you want it to match anything, you have to use :any.


whats wrong with this? - El Forum - 01-10-2010

[eluser]dadamssg[/eluser]
oh ok. thanks man