Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: php mysql query

  1. #1
    Regular Coder
    Join Date
    Jan 2007
    Posts
    137
    Thanks
    5
    Thanked 0 Times in 0 Posts

    php mysql query

    am getting an error
    Unknown column '$code' in 'where clause'

    PHP Code:
    <?php 
            
    $server 
    'localhost'// MySQL hostname
    $username 'root'// MySQL username
    $password ''// MySQL password
    $dbname 'ip2l'// MySQL db name

    // connecting to database
    $db mysql_connect($server$username$password) or die(mysql_error());
    mysql_select_db($dbname) or die(mysql_error());

            
    $ip =    $_SERVER['REMOTE_ADDR'];
            
    $ip "59.96.40.247"// assigned dummy ip to test the script localy
            
    echo $ip;
            echo 
    '<br/>';
            
    $numbers preg_split"/\./"$ip);
            
    $code=($numbers[0] * 16777216) + ($numbers[1] * 65536) + ($numbers[2] * 256) + ($numbers[3]);
            echo 
    $code;
            echo 
    '<br/>';
            
            
    $sql 'SELECT * FROM `ipcountryregioncitylatitudelongitudeispdomain` WHERE ipFROM < $code && ipTO > $code';
            
    $get_info_result mysql_query($sql$db) or die(mysql_error());
            
    $info mysql_fetch_array($get_info_result);
            
            
    $country_code $info[countrySHORT];
            
    $country_name $info[countryLONG];
            
    $region $info[ipREGION];
            
    $city $info[ipCITY];
            
    $latitude $info[ipLATITUDE];
            
    $longitude $info[ipLONGITUDE];
            
    $isp $info[ipISP];
            
    $domain $info[ipDOMAIN];
            echo 
    $country_name;
            
    ?>
    am getting the error from this code can u plz correct it
    its a ip to geo based locator...
    where the code is the converted ip number which should be between the rage of ipFROM and ipTO

    PHP Code:
    $sql 'SELECT * FROM `ipcountryregioncitylatitudelongitudeispdomain` WHERE ipFROM < $code && ipTO > $code'

  • #2
    New Coder
    Join Date
    Sep 2007
    Location
    India
    Posts
    72
    Thanks
    1
    Thanked 2 Times in 2 Posts
    $sql = 'SELECT * FROM `ipcountryregioncitylatitudelongitudeispdomain` WHERE ipFROM < $code && ipTO > $code';
    change to

    $sql = 'SELECT * FROM `ipcountryregioncitylatitudelongitudeispdomain` WHERE ipFROM < $code AND ipTO > $code';
    cheers
    - Developer from India

    Firefox 2.0

  • #3
    Regular Coder
    Join Date
    Jan 2007
    Posts
    137
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Code:
    $sql = 'SELECT * FROM `ipcountryregioncitylatitudelongitudeispdomain` WHERE ipFROM < $code AND ipTO > $code';
    on changing to the above

    Unknown column '$code' in 'where clause'
    am getting the same error

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    If you print your query (echo $sql;) you may see the portion ipFROM < $code remains as such, which is causing the error. You have to pass the value of $code. So Chage it like

    Code:
    $sql = "SELECT * FROM `ipcountryregioncitylatitudelongitudeispdomain` WHERE ipFROM < '$code' && ipTO > '$code' ";
    PS: reaally surprised to see you table name
    Last edited by abduraooft; 02-23-2008 at 06:58 AM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Regular Coder
    Join Date
    Jan 2007
    Posts
    137
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    If you print your query (echo $sql;) you may see the portion ipFROM < $code remains as such, which is causing the error. You have to pass the value of $code. So Chage it like

    Code:
    $sql = "SELECT * FROM `ipcountryregioncitylatitudelongitudeispdomain` WHERE ipFROM < '$code' && ipTO > '$code' ";
    PS: reaally surprised to see you table name
    PHP Code:
    $sql "SELECT * FROM ipcountryregioncitylatitudelongitudeispdomain WHERE ipTO >=$code AND ipFROM <=$code"

    i ddint notice.... for $sql = ' '; is wht i used n it should be $sql = " "; since am passing variables..

    thanx abduraooft

    the table name is so since i just imported wht i got off the net... not my creation...


  •  

    Posting Permissions

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