Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2009
    Posts
    3

    Unanswered: mySQL Query Probleme

    H`i... I`m working on a members only site .... I want at login to check if an IP is banned or not ... for this I used the following syntax:

    PHP Code:

    $ip 
    getip(); //GET USERS IP



        //Check IP bans    

        
    $nip ip2long($ip);

        
    $res mysql_query("SELECT * FROM bans WHERE $nip >= first AND $nip <= last")  or die(mysql_error());
     
    //first and last are columns in bans table
        
    if (mysql_num_rows($res) > 0) {

            
    $row mysql_fetch_array($res);

            
    header("HTTP/1.0 403 Forbidden");

            echo 
    "<html><head><title>Forbidden</title></head><body><h1>Forbidden</h1>Unauthorized IP address.<br />".

            
    "Reason for banning: $row[comment]</body></html>";

            die;

        } 

    If I try to access the site I receive the following error:

    Code:
    Mysql sintax error. Try to find corect sintax to use near 'SELECT * FROM bans WHERE $nip >= first AND $nip <= last'.
    I`m using mysql-server-5.0 on a Ubuntu machine
    Last edited by Lupu; 11-11-09 at 09:22.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so what is the actual message
    what is the actual SQL that is being sent to the SQL engine

    you might want to try the "between" syntax
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Nov 2009
    Posts
    3
    Quote Originally Posted by Lupu View Post


    If I try to access the site I receive the following error:

    Code:
    Mysql sintax error. Try to find corect sintax to use near 'SELECT * FROM bans WHERE $nip >= first AND $nip <= last'.
    with between is thesame erorr...only that the mesage is

    Code:
    Mysql sintax error. Try to find corect sintax to use near 'SELECT * FROM bans WHERE $nip between first AND  last'.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so what is the actual SQL you are sending to the SQL engine
    not the script but the SQL executed

    PHP Code:
    $strSQL "SELECT * FROM bans WHERE $nip >= first AND $nip <= last";

    $res mysql_query($strSQL)  //or die(mysql_error());
    //for now
    die (echo $strSQL."\n".$mysql_errno()."\n".$mysql_error()); 
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Nov 2009
    Posts
    3
    Quote Originally Posted by healdem View Post
    so what is the actual SQL you are sending to the SQL engine
    not the script but the SQL executed

    PHP Code:
    $strSQL "SELECT * FROM bans WHERE $nip >= first AND $nip <= last";

    $res mysql_query($strSQL)  //or die(mysql_error());
    //for now
    die (echo $strSQL."\n".$mysql_errno()."\n".$mysql_error()); 


    tx a lot.... working now with your advice...... only 1 change to your script:
    i`ve changed
    PHP Code:

    $strSQL 
    "SELECT * FROM bans WHERE $nip >= first AND $nip <= last"
    with

    PHP Code:

    $strSQL 
    "SELECT * FROM bans WHERE '$nip' >= first AND '$nip' <= last"

    i don`t know if that is ok... i mean if is realy chek if IP is banned.. but i can see mi site now and I can continue mi work...
    sorry for mi bad eng

Posting Permissions

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