jimmy06 Posted July 22, 2007 Share Posted July 22, 2007 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 https://forums.phpfreaks.com/topic/61248-ban-code/ Share on other sites More sharing options...
trq Posted July 22, 2007 Share Posted July 22, 2007 Using just the standard mysql functions you would use mysql_insert_id. Link to comment https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-304728 Share on other sites More sharing options...
jimmy06 Posted July 22, 2007 Author Share Posted July 22, 2007 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 https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-304733 Share on other sites More sharing options...
trq Posted July 22, 2007 Share Posted July 22, 2007 Well, you would use mysql_last_id to get the id of the last inserted ip. This would then give you the record for which you would SELECT the ip in order to do another INSERT. Without clearer descriptions your going to get vague (guesses at) answers. Link to comment https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-304737 Share on other sites More sharing options...
jimmy06 Posted July 22, 2007 Author Share Posted July 22, 2007 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 https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-304739 Share on other sites More sharing options...
trq Posted July 22, 2007 Share Posted July 22, 2007 Sorry... thats just a typo / error. Should be mysql_insert_id. Link to comment https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-304752 Share on other sites More sharing options...
jimmy06 Posted July 22, 2007 Author Share Posted July 22, 2007 sorry please read my edit :-) above insert_id is Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query so i dont think this will help :-) Link to comment https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-304753 Share on other sites More sharing options...
trq Posted July 22, 2007 Share Posted July 22, 2007 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 https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-304759 Share on other sites More sharing options...
jimmy06 Posted July 22, 2007 Author Share Posted July 22, 2007 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 https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-304773 Share on other sites More sharing options...
jimmy06 Posted July 22, 2007 Author Share Posted July 22, 2007 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 https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-304786 Share on other sites More sharing options...
trq Posted July 22, 2007 Share Posted July 22, 2007 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 https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-304790 Share on other sites More sharing options...
jimmy06 Posted July 22, 2007 Author Share Posted July 22, 2007 i now get this result "Array","1185129447","1185129437","WEBSERVER","WEBSERVER" Link to comment https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-304807 Share on other sites More sharing options...
trq Posted July 22, 2007 Share Posted July 22, 2007 Are you trying to echo $q? Post your code. Link to comment https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-304812 Share on other sites More sharing options...
jimmy06 Posted July 22, 2007 Author Share Posted July 22, 2007 i think i need a result thing no ? lol Link to comment https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-304814 Share on other sites More sharing options...
trq Posted July 22, 2007 Share Posted July 22, 2007 Yes. Link to comment https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-304815 Share on other sites More sharing options...
jimmy06 Posted July 22, 2007 Author Share Posted July 22, 2007 ok then ill give it ago at that then, sorry i really dont know php and learning the fun way thanks so far :-P Link to comment https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-304817 Share on other sites More sharing options...
trq Posted July 22, 2007 Share Posted July 22, 2007 Yeah... everyone's gotta start somewhere. Good luck. Link to comment https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-304820 Share on other sites More sharing options...
jimmy06 Posted July 22, 2007 Author Share Posted July 22, 2007 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 https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-304835 Share on other sites More sharing options...
jimmy06 Posted July 22, 2007 Author Share Posted July 22, 2007 i should be using this correct ? mysql_fetch_array Link to comment https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-304838 Share on other sites More sharing options...
jimmy06 Posted July 23, 2007 Author Share Posted July 23, 2007 RESOLVED Link to comment https://forums.phpfreaks.com/topic/61248-ban-code/#findComment-305092 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.