BillyBoB Posted July 13, 2008 Share Posted July 13, 2008 My problem is I have two tables with different information about the user but the id's need to be the same. I think there is a way of retrieving the last id from the query, but I don't know exactly. I have one query go then I want to have the id set by the first query for the second. I really want to do this for security so incase the id's get off somewhere somehow I do not have to go and manually fix 100's of user id's. My code is as follows: <?php $sql = "INSERT INTO `user_profiles` (`username`,`email`"; if($this->avatar) $sql .= ",`avatar`"; if($this->quote) $sql .= ",`quote`"; if($this->signature) $sql .= ",`signature`"; $sql .= ") VALUES('".$this->username."','".$this->email."'"; if($this->avatar) $sql .= ",'".$this->avatar."'"; if($this->quote) $sql .= ",'".$this->quote."'"; if($this->signature) $sql .= ",'".$this->signature."'"; $sql .= ")"; $query = mysql_query($sql); //retrieve id from this query //set it in this one. $validation = substr(sha1(rand()), rand(0,35), 5); $iplong = ip2long($_SERVER['REMOTE_ADDR']); $sql2 = "INSERT INTO `user_files` (`validated`,`userip`,`password`) VALUES('".$validation."','".$iplong."','".$this->password."')"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/114518-solved-retrieving-last-id-from-query/ Share on other sites More sharing options...
wildteen88 Posted July 13, 2008 Share Posted July 13, 2008 mysql_insert_id() Quote Link to comment https://forums.phpfreaks.com/topic/114518-solved-retrieving-last-id-from-query/#findComment-588882 Share on other sites More sharing options...
JasonLewis Posted July 13, 2008 Share Posted July 13, 2008 mysql_insert_id() Edit: 15 seconds. Quote Link to comment https://forums.phpfreaks.com/topic/114518-solved-retrieving-last-id-from-query/#findComment-588883 Share on other sites More sharing options...
BillyBoB Posted July 13, 2008 Author Share Posted July 13, 2008 Thanks a lot sorry about bothering you on such a nooby question its 7 am here and I haven't been to bed. So I am about to pass out just needed to get it done so I ask forum with infinite knowledge. Mostly because this forum is so big and has a lot of people lol. Quote Link to comment https://forums.phpfreaks.com/topic/114518-solved-retrieving-last-id-from-query/#findComment-588884 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.