Foros del Web » Programando para Internet » PHP »

no consigo que funcione me tiene loco

Estas en el tema de no consigo que funcione me tiene loco en el foro de PHP en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 09/06/2007, 05:27
 
Fecha de Ingreso: junio-2007
Mensajes: 10
Antigüedad: 16 años, 10 meses
Puntos: 0
no consigo que funcione me tiene loco

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-
  #2 (permalink)  
Antiguo 09/06/2007, 05:39
Avatar de Yranac  
Fecha de Ingreso: junio-2007
Mensajes: 125
Antigüedad: 16 años, 10 meses
Puntos: 1
Re: no consigo que funcione me tiene loco

Sinceramente no he leido todo tu código porque voy muy mal de tiempo 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.
(siento no poder darte la url pero mira en php.net su uso)
  #3 (permalink)  
Antiguo 09/06/2007, 05:49
Avatar de pzin
Moderata 😈
 
Fecha de Ingreso: julio-2002
Ubicación: Islas Canarias
Mensajes: 10.488
Antigüedad: 21 años, 8 meses
Puntos: 2114
Re: no consigo que funcione me tiene loco

¿Pero qué error te da?

Por lo pronto yo solo veo que hace falta una comillas donde declaras $result3. Y los mysql_query(), ¿no hay que cerrarlos con ) también?
  #4 (permalink)  
Antiguo 09/06/2007, 05:53
Avatar de vb2005  
Fecha de Ingreso: noviembre-2005
Ubicación: Paderborn - Alemania
Mensajes: 566
Antigüedad: 18 años, 4 meses
Puntos: 24
Re: no consigo que funcione me tiene loco

si, hay muchos errores d parentesis y punto y coma pero la solucion de Yranac es la más efectiva
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:15.