Re: Lost in PHP (part 1) ---- Sequle to Lost in Query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



How can I convert it to an integer aslong as it is only a number in the string?



On Mon, 11 Oct 2004 13:19:40 -0400, John Holmes
<holmes072000@xxxxxxxxxxx> wrote:
> GH wrote:
> 
> > Now I m perplexed time 10!
> >
> >    I run the code that follows.... this time providing a query string
> > of admin_template.php?api=101
> >
> > I have an if statement that tests if $_GET['api'] == 0 .... if it is
> > true I have it listing options, else it queries the database with that
> > ID and loads the associated file.
> 
> You have a lot more tests than that...
> 
> > However it does not seem to execute the else....
> >
> > I: thought that the value may of been wrong so I used        echo
> > $_GET['api']; and it returned 101
> 
> use var_dump($_GET['api']) and it may give you a clue. Your is_int()
> test is going to fail each time because anything passed through $_GET or
>  $_POST is a string.
> 
> FYI, you could essentially replace all of those tests you do on
> $_GET['api'] with
> 
> if(empty($_GET['api']))
> {
>   echo 'bad value';
>   //or select everything from table ?
> }
> else
> {
>   $input['api'] = (int)$_GET['api'];
>   $query = "SELECT * FROM yourtable WHERE api = {$input['api']}";
>   ...
> }
> 
> --
> 
> ---John Holmes...
> 
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
> 
> php|architect: The Magazine for PHP Professionals â www.phparch.com
> 
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux