Jump to content

Ban code :-)


jimmy06

Recommended Posts

That it is lol, i figured it out BUT came across another problem the place where i have to inject the ip into the database is writen like this

 

elseif($_GET['action']=='ban'){
        $DB->query("INSERT into account_banned (id, bandate, unbandate, bannedby, banreason, active) values (?d, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()-10, 'WEBSERVER', 'WEBSERVER', 1)",$_GET['id']);
redirect('index.php?n=admin&sub=members&id='.$_GET['id'],1);

I've made the statement to inject the ip that being

 

$DB->query("INSERT into ip_banned (ip, bandate, unbandate, bannedby, banreason) values (?q, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()-10, 'WEBSERVER', 'WEBSERVER')",$_GET['id']);

But cant work out how to grab the ip from the db and inject it back in a different table i tried doing something along the lines of

 

$q = $DB->query("SELECT last_ip FROM account WHERE id='?d'");

But just got an empty feild for the feild ip but the rest updated correctly.

 

Thanks

 

Rob


Link to comment
Share on other sites

insert_id ? i dont need to insert an id i need to insert an ip, the code need to get the ip from the database last_ip feild in table account and then insert it into the table ip_banned i got EVERYthing but the inserting ip bit working :-) just wondered if you could give me any leads :-)

Link to comment
Share on other sites

Table 1

 

Field          Type                 Collation        Null    Key     Default              Extra           Privileges                       Comment   
-------------  -------------------  ---------------  ------  ------  -------------------  --------------  -------------------------------  ----------
id             bigint(20) unsigned  NULL                     PRI     (NULL)               auto_increment  select,insert,update,references  Identifier
username       varchar(32)          utf8_general_ci          UNI                                          select,insert,update,references            
I              varchar(40)          utf8_general_ci                                                       select,insert,update,references            
gmlevel        tinyint(3) unsigned  NULL                     MUL     0                                    select,insert,update,references            
sessionkey     longtext             utf8_general_ci  YES             (NULL)                               select,insert,update,references            
v              longtext             utf8_general_ci  YES             (NULL)                               select,insert,update,references            
s              longtext             utf8_general_ci  YES             (NULL)                               select,insert,update,references            
email          varchar(255)         utf8_general_ci                                                       select,insert,update,references            
joindate       timestamp            NULL             YES             CURRENT_TIMESTAMP                    select,insert,update,references            
last_ip        varchar(30)          utf8_general_ci                  127.0.0.1                            select,insert,update,references            
failed_logins  int(11) unsigned     NULL                             0                                    select,insert,update,references            
locked         tinyint(3) unsigned  NULL                             0                                    select,insert,update,references            
last_login     timestamp            NULL             YES             0000-00-00 00:00:00                  select,insert,update,references            
online         tinyint(4)           NULL                             0                                    select,insert,update,references            
tbc            tinyint(3) unsigned  NULL                             0                                    select,insert,update,references            
mutetime       bigint(40) unsigned  NULL                             0                                    select,insert,update,references            

 

Table 2

 

Field      Type          Collation        Null    Key     Default    Extra   Privileges                       Comment
---------  ------------  ---------------  ------  ------  ---------  ------  -------------------------------  -------
ip         varchar(32)   utf8_general_ci          PRI     127.0.0.1          select,insert,update,references         
bandate    bigint(40)    NULL                     PRI     0                  select,insert,update,references         
unbandate  bigint(40)    NULL                             0                  select,insert,update,references         
bannedby   varchar(50)   utf8_general_ci                  [Console]          select,insert,update,references         
banreason  varchar(255)  utf8_general_ci                  no reason          select,insert,update,references         

 

i need to go into table 1 feild last_ip and then insert it into table 2 ip the rest of it works fine :-)

Link to comment
Share on other sites

so i dont think this will help :-)

 

Read my previous reply.

 

When you do the INSERT, you would then do a SELECT to get the last ip inserted using mysql_insert_id in the where clause. You now have the ip, and simply do another INSERT.

 

Of course to do this properly you should use database normalization. you really don't need the ip in more than one table.

 

The book in my signiture has a section which describes database normalization techniques. This would however involve some serious database redesign.

Link to comment
Share on other sites

the last_ip is in a table though ? that table being account i dont relate the the account table anywhere in that code, i still fail to see the link between mysql_insert_id and the table last_ip (wich may i add wont always be the last ip inserted into the table, just the last ip that a paticular user access the site or game server with)

 

Regards,

 

Rob

Link to comment
Share on other sites

I think i need to point out order or the MYSQL code

 

code would be as follows

 

elseif($_GET['action']=='ban'){
        $DB->query("INSERT into account_banned (id, bandate, unbandate, bannedby, banreason, active) values (?d, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()-10, 'WEBSERVER', 'WEBSERVER', 1)",$_GET['id']);
redirect('index.php?n=admin&sub=members&id='.$_GET['id'],1);
$q = $DB->query("SELECT last_ip FROM account WHERE id='?d'");
$DB->query("INSERT into ip_banned (ip, bandate, unbandate, bannedby, banreason) values ($q, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()-10, 'WEBSERVER', 'WEBSERVER')",$_GET['id']);

 

Hope that makes it a little clearer

Link to comment
Share on other sites

Ok... in your original post you say you've tried....

 

$q = $DB->query("SELECT last_ip FROM account WHERE id='?d'");

 

Try....

 

$q = $DB->query("SELECT last_ip FROM account WHERE id=" . mysql_insert_id());

Link to comment
Share on other sites

I still end up with an emtpy field :-(

 

$row = mysql_result( $q, 1 );
$DB->query("INSERT into ip_banned (ip, bandate, unbandate, bannedby, banreason) values ('$row', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()-10, 'WEBSERVER', 'WEBSERVER')",$_GET['id']);

 

But i did notice this ?

 

Note:  The value of the MySQL SQL function LAST_INSERT_ID() always contains the most recently generated AUTO_INCREMENT value, and is not reset between queries.

 

but when changing to that type my page fail to load correctly ie; stays white lol

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.