Ver Mensaje Individual
  #10 (permalink)  
Antiguo 09/06/2007, 05:00
elitepep
 
Fecha de Ingreso: junio-2007
Mensajes: 10
Antigüedad: 16 años, 10 meses
Puntos: 0
Re: problemas con ID autoincrementable

Me sigue fallando no tengo .... de hacerlo. Quiero leer la id que se añadio en la ficha recien insertada y crear una ficha en la otra tabla y solo e da errores.
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 "'";
  
$rowmysql_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));
}
?> 
solo me da errores sin parar en donde marque con negrita y no hace lo que se supone busco que me lea la id de la fila que acabo de insertar y que me cree una ficha en la otra tabla en la que este la id_pj = a la id de la ficha-