SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP allow only Numbers

    Hello, im using mod_rewrite to acces site.com/index.php?news=10 at site.com/news/10 ,

    and $id=$_Get['id'], inserted in sql, to recieve data, but when you go to site.com/news/cow, giving some errors, so i only wanna allows numbers in the $id, but how?

    thnx .. Aprominax

  2. #2
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $id = (int) $_GET['id']; 

  3. #3
    SitePoint Addict CommanderZ's Avatar
    Join Date
    Apr 2006
    Location
    Czech Republic
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You may check the input using is_numeric

    PHP Code:
    is_numeric($_GET["id"]) or die("Wrong input"); 

  4. #4
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is_numeric($_GET["id"]) works perfect, thnx


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •