Código PHP:
   / *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
  $MM_dupKeyRedirect="error.php";
  $loginUsername = $_POST['nick'];
  $LoginRS__query = "SELECT nick FROM usuarios WHERE nick='" . $loginUsername . "'";
  mysql_select_db($database_ninjarpg, $ninjarpg);
  $LoginRS=mysql_query($LoginRS__query, $ninjarpg) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
 
  //if there is a row in the database, the username was found - can not add the requested username
  if($loginFoundUser){
    $MM_qsChar = "?";
    //append the username to the redirect page
    if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
    $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
    header ("Location: $MM_dupKeyRedirect");
    exit;
  }
}
 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
 
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
 
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO usuarios (nick, password, nombre, email, pj_carac) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['nick'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['nombre'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['pj_carac'], "text"));
 
  
  
}
 
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
  $insertSQL = sprintf("INSERT INTO usuarios (nick, password, nombre, email, pj_carac) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['nick'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['nombre'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['pj_carac'], "text"));
mysql_select_db($database_ninjarpg, $ninjarpg);
   $Result1 = mysql_query($insertSQL, $ninjarpg) or die(mysql_error());
  $result2 = mysql_query("select id from usuarios where nick='" . $loginUsername . "'";
  $row= mysql_fetch_array($result2);
  $result3 = mysql_query("insert into pj_carac (id_pj,frz,des,int,mga,c_magia) values ($row[1],0,0,0,0,0);
  $insertGoTo = "login.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?> 
     
 

 pero existe una función en php que te da el id del último insert realizado y que es mysql_insert_id ahí tendrás el ultimo id sin necesidad de consultarlo tu de nuevo.
 pero existe una función en php que te da el id del último insert realizado y que es mysql_insert_id ahí tendrás el ultimo id sin necesidad de consultarlo tu de nuevo.


