Jump to content

[SOLVED] Retrieving last id from query.


BillyBoB

Recommended Posts

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."')";
?>

Link to comment
Share on other sites

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.

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.