If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > mySQL Query Probleme

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-11-09, 05:57
Lupu Lupu is offline
Registered User
 
Join Date: Nov 2009
Posts: 3
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 08:22.
Reply With Quote
  #2 (permalink)  
Old 11-11-09, 06:38
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,258
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 my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 11-11-09, 08:21
Lupu Lupu is offline
Registered User
 
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'.
Reply With Quote
  #4 (permalink)  
Old 11-11-09, 08:52
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,258
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 my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #5 (permalink)  
Old 11-11-09, 10:33
Lupu Lupu is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On