Foros del Web » Programando para Internet » PHP »

No ingresan los datos por formulario

Estas en el tema de No ingresan los datos por formulario en el foro de PHP en Foros del Web. Hola bueno estoy tratando hace muchisimo rato de ingresar unos datos a la DB pero no puedo me devuelve la pagina diciendo que muchas gracias ...
  #1 (permalink)  
Antiguo 02/03/2005, 13:58
Avatar de CHILENOCES  
Fecha de Ingreso: octubre-2001
Ubicación: Mmm paseando por la vida
Mensajes: 491
Antigüedad: 22 años, 6 meses
Puntos: 0
No ingresan los datos por formulario

Hola bueno estoy tratando hace muchisimo rato de ingresar unos datos a la DB pero no puedo me devuelve la pagina diciendo que muchas gracias y todo como si los hubiese ingresado pero al ir a verificar en el phpMyAdmin no me muestra nada en la DB

el codigo es el siguiente:

<?php
include("conexion_db.php");
if($accion= "lenguaje")
{

$sql = "INSERT INTO notas_lenguaje (id,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10 ,
11,
12,
13 ,
14 ,
pd) VALUES ( '$id',
'$1',
'$2',
'$3',
'$4',
'$5',
'$6',
'$7',
'$8',
'$9',
'$10' ,
'$11',
'$12',
'$13' ,
'$14' ,
'$pd')";
$result = mysql_query($sql);
echo "<p>Muchas Gracias</p>";
}

?>


La estructura de la tabla es :

CREATE TABLE `notas_lenguaje` (
`id` int(11) NOT NULL auto_increment,
`1` varchar(250) NOT NULL default '',
`2` varchar(250) NOT NULL default '',
`3` varchar(250) NOT NULL default '',
`4` varchar(250) NOT NULL default '',
`5` varchar(250) NOT NULL default '',
`6` varchar(250) NOT NULL default '',
`7` varchar(250) NOT NULL default '',
`8` varchar(250) NOT NULL default '',
`9` varchar(250) NOT NULL default '',
`10` varchar(250) NOT NULL default '',
`11` varchar(250) NOT NULL default '',
`12` varchar(250) NOT NULL default '',
`13` varchar(250) NOT NULL default '',
`14` varchar(250) NOT NULL default '',
`pd` varchar(250) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;


Y el Formulario es :

<FORM METHOD=POST ACTION="ingresar.php?accion=lenguaje">
<tr bgcolor="#FFFFFF">
<td width="35" height="19"><div align="center">
<input type="text" size="1" maxlength="3" name="1">
</div></td>
<td width="35" height="19"><div align="center">
<input type="text" size="1" maxlength="3" name="2">
</div></td>
<td width="35" height="19"><div align="center">
<input type="text" size="1" maxlength="3" name="3">
</div></td>
<td width="35" height="19"><div align="center">
<input type="text" size="1" maxlength="3" name="4">
</div></td>
<td width="35" height="19"><div align="center">
<input type="text" size="1" maxlength="3" name="5">
</div></td>
<td width="35" height="19"><div align="center">
<input type="text" size="1" maxlength="3" name="6">
</div></td>
<td width="35" height="19"><div align="center">
<input type="text" size="1" maxlength="3" name="7">
</div></td>
<td width="35" height="19"><div align="center">
<input type="text" size="1" maxlength="3" name="8">
</div></td>
<td width="35" height="19"><div align="center">
<input type="text" size="1" maxlength="3" name="9">
</div></td>
<td width="35" height="19"><div align="center">
<input type="text" size="1" maxlength="3" name="10">
</div></td>
<td width="35" height="19"><div align="center">
<input type="text" size="1" maxlength="3" name="11">
</div></td>
<td width="35" height="19"><div align="center">
<input type="text" size="1" maxlength="3" name="12">
</div></td>
<td width="35" height="19"><div align="center">
<input type="text" size="1" maxlength="3" name="13">
</div></td>
<td width="35" height="19"><div align="center">
<input type="text" size="1" maxlength="3" name="14">
</div></td>
<td width="35"><div align="center">
<input type="text" size="1" maxlength="3" name="pd">
</div></td>
<td width="35" height="19"><div align="center"></div></td>
<td width="35"><INPUT TYPE="submit" value="Enviar"></td>
</tr>
</form>

Realmente no veo errores en la sintaxis de PHP me estoy ya poniendo medio loco con eso alguien q desea aportar por fisss muchas gracias.

Saludos
__________________
ChilenoCesar Looking for something new...
  #2 (permalink)  
Antiguo 02/03/2005, 14:22
 
Fecha de Ingreso: julio-2004
Mensajes: 194
Antigüedad: 19 años, 9 meses
Puntos: 1
Código PHP:

<?php
include("conexion_db.php");

if(
$_GET[accion]== "lenguaje"){  //pasas el valor de accion por URL y por eso se lee tipo get
   
$sql "INSERT INTO notas_lenguaje (id,1,2,3,4,5,6,7,8,9,10,11,12,13,14,pd)
           VALUES ('$_POST[1]','$_POST[2]','$_POST[3]','$_POST[4]','$_POST[5]','$_POST[6]','$_POST[7]','$_POST[8]','$_POST[9]','$_POST[10]','$_POST[11]','$_POST[12]','$_POST[13]','$_POST[14]','$_POST[pd]')"
;

        if(
$result mysql_query($sql))
           echo 
"<p>Muchas Gracias</p>";
         else
           echo 
"<p>ERROR, the information could not be added because: ".mysql_error()."</p>";
}

?>
Tienes que usar los arreglos... eeehh. no recuerdo el nombre pero son los $_POST[] cuando haces el envio tipo post y $_GET[] cuando es tipo get obviamente. alguien mas del foro que te lo explique mejor y me refresque un poco la memoria e la parte teorica.

Tambien mira como se hace la validacion para ver si en verdad lo agrego o no y la forma en que devuelve el error. Ah, cuando la id es autonomerica no tiemes que ponerla en la sentencia SQL.

Espero te funcione ahora el codigfo pues no lo probe.

Saludos y suerte.

PD: perdon por lo desordenado del source pero el camo del foro no ayuda
__________________
"Hay Algo Activo en el piso de Abajo..."

K-Seraph Blog

Última edición por k-seraph; 02/03/2005 a las 14:30
  #3 (permalink)  
Antiguo 02/03/2005, 14:42
Avatar de CHILENOCES  
Fecha de Ingreso: octubre-2001
Ubicación: Mmm paseando por la vida
Mensajes: 491
Antigüedad: 22 años, 6 meses
Puntos: 0
ERROR, the information could not be added because: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '1,2,3,4,5,6,7,8,9,10,11,12,13,14,pd) VALUES ('22',


Eso me devolvió y ese 22 fue un numero q puse en el formulario antes de presionar el boton Enviar no entiendo por q pero no me deja ingresar los campos, tengo otro formulario similar al q puse yo en el primer post y funciona todo ok ...
__________________
ChilenoCesar Looking for something new...
  #4 (permalink)  
Antiguo 02/03/2005, 14:49
Avatar de CHILENOCES  
Fecha de Ingreso: octubre-2001
Ubicación: Mmm paseando por la vida
Mensajes: 491
Antigüedad: 22 años, 6 meses
Puntos: 0
Bueno si no completo ningun campo el error es asi:

ERROR, the information could not be added because: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '1,2,3,4,5,6,7,8,9,10,11,12,13,14,pd) VALUES ( '', '',
__________________
ChilenoCesar Looking for something new...
  #5 (permalink)  
Antiguo 02/03/2005, 14:53
 
Fecha de Ingreso: julio-2004
Mensajes: 194
Antigüedad: 19 años, 9 meses
Puntos: 1
Error "corregido" y codigo mejorado

Código PHP:

<?php
include("conexion_db.php");

if(
$_GET[accion]== "lenguaje"){
    
$result mysql_query("INSERT INTO notas_lenguaje (1,2,3,4,5,6,7,8,9,10,11,12,13,14,pd)
                 VALUES ('$_POST[1]','$_POST[2]','$_POST[3]','$_POST[4]','$_POST[5]','$_POST[6]','$_POST[7]','$_POST[8]','$_POST[9]','$_POST[10]','$_POST[11]','$_POST[12]','$_POST[13]','$_POST[14]','$_POST[pd]')"
)

                     or die (
"<p>ERROR, the information could not be added because: ".mysql_error()."</p>");

        if(
$result)
           echo 
"<p>Muchas Gracias</p>";

}
?>
Detecte un error en el codigo que creo que es lo que te genero el error y ademas como puedes ver realize unos cambios para mejor desenpeño.

Informame si ahora funciona.
__________________
"Hay Algo Activo en el piso de Abajo..."

K-Seraph Blog
  #6 (permalink)  
Antiguo 02/03/2005, 16:14
Avatar de CHILENOCES  
Fecha de Ingreso: octubre-2001
Ubicación: Mmm paseando por la vida
Mensajes: 491
Antigüedad: 22 años, 6 meses
Puntos: 0
ERROR, the information could not be added because: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '1,2,3,4,5,6,7,8,9,10,11,12,13,14,pd) VALUES

Ahora sale VALUES y nada mas al costado pero sigue sin funcionar :( realmente no soy nuevo en esto de PHP y un simple INSERT tan complicado me esta volviendo loco.

Saludos y ahi veamos k-seraph cualquier avance te aviso igual tu gracias.
__________________
ChilenoCesar Looking for something new...
  #7 (permalink)  
Antiguo 03/03/2005, 10:36
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Te recomendaría que usases una variable para tu sentencia SQL:

$sql="INSERT ......";

y de ahí atacas tu mysql_query() or die (mysql_error())

así podras hacer un "echo" a $Sql y ver la sintax SQL exacta que estás componiendo para ver como queda. El error ya sabes que es de sintax SQL .. así que lo ideal sería resolver el problema en el foro de Base de datos (con el SQL generado y que vas a ver en echo $sql)


Un saludo,

Última edición por Cluster; 03/03/2005 a las 10:37
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 10:43.