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 Quote Link to comment 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. Quote Link to comment 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 :-) Quote Link to comment 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. Quote Link to comment 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 :-) Quote Link to comment 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. Quote Link to comment 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 :-) Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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()); Quote Link to comment 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" Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
trq Posted July 22, 2007 Share Posted July 22, 2007 Yes. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
jimmy06 Posted July 23, 2007 Author Share Posted July 23, 2007 RESOLVED Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.