Título: problema con formulario para insertar informacion en base de datos Publicado por: abbyblack123 en 24 Abril 2013, 16:29 pm Hola tengo un problema al intentar ingresar datos de un formulario a una tabla, me dice que se inserto satisfactoriamente pero no lo hace, este es el codigo:
<? session_start(); ?> <html> <head> <title>Agregar nuevo registro</title> </head> <body bgcolor="#A9BCF5" text="000000"> <center><font size="+2"><h3>::::ALTAS:::: </h3></font></center> <br> <?php include ("conexion.php"); $link=Conectarse(); echo "<br>"; echo "<form action= ''method='post'>"; echo "CLAVE"; echo "<input name='clave_pe' type='text' size='12' maxlenght='14'>"; echo "<br>"; echo "<br>"; echo "ARTICULO"; echo "<input name='art_pe' type='text' size='20' maxlenght='20'>"; echo "<br>"; echo "<br>"; echo "CANTIDAD"; echo "<input name='cant_pe' type='text' size='1' maxlenght='1'>"; echo "<br>"; echo "<br>"; echo "MARCA"; echo "<input name='marca_pe' type='text' size=20' maxlenght='30'>"; echo "<br>"; echo "<br>"; echo "MODELO"; echo "<input name='modelo_pe' type='text' size='20' maxlenght='30'>"; echo "<br>"; echo "<br>"; echo "NUMERO DE SERIE"; echo "<input name='nume_pe' type='text' size='20' maxlenght='20'>"; echo "<br>"; echo "<br>"; echo "COLOR"; echo "<input name='color_pe' type='text' size='10' maxlenght='10'>"; echo "<br>"; echo "<br>"; echo "ESPECIFICACIONES"; echo "<input name='espec_pe' type='text' size='40' maxlenght='50'>"; echo "<br>"; echo "<br>"; echo "NUMERO DE INVENTARIO"; echo "<input name='numer_pe' type='text' size='14' maxlenght='14'>"; echo "<br>"; echo "<br>"; echo "NUMERO DE EQUIPO"; echo "<input name='numero_pe' type='text' size='10' maxlenght='10'>"; echo "<br>"; echo "<br>"; echo "<center> <INPUT TYPE='submit' name=GUARDAR VALUE='GUARDAR'</center>"; echo " <a href='frames.html'> </a>"; if ($_POST ['GUARDAR']){ $fec=$_SESSIOn ["fecha"]; $clave_per=$_POST['clave_pe']; $art_per=$_POST['art_pe']; $cant_per=$_POST['cant_pe']; $marca_per=$_POST['marca_pe']; $modelo_per=$_POST['modelo_pe']; $nume_per=$_POST['nume_pe']; $color_per=$_POST['color_pe']; $espec_per=$_POST['espec_pe']; $numer_per=$_POST['numer_pe']; $numero_per=$_POST['numero_pe']; if($clave_per=='0' || $art_per=="" || $cant_per=="" || $marca_per=="" || $modelo_per=="" || $nume_per=="" || $color_per=="" || $espec_per=="" || $numer_per=="" || $numero_per=="" ) { echo '<script languaje=javascript>'; echo 'alert (\'NO SE PUEDE GUARDAR, CAMPOS VACIOS!!\');'; echo 'window.location="altas.php";'; echo '</script>';} else { $consulta=mysql_query("select * from equipo where (clave='$clave_per') order by clave",$link); $numeroRegistros=mysql_num_rows($consulta); if ($numeroRegistros>0) { echo '<script languaje=javascript>'; echo 'alert(\'LA CLAVE YA EXISTE! \');'; echo 'window.location="altas.php";'; echo '</script>'; echo "<br>"; } else { mysql_query("INSERT INTO equipo (clave,articulo,cantidad, marca, modelo, numero_serie, color, especificaciones, numero_inventario, numero_equipo) VALUES ('$clave_per','$art_per','$cant_per','$marca_per','$modelo_per','$nume_per','$color_per','$espec_per','$numer_per','$numero_per')",$link); echo '<script languaje=javascript>'; echo 'alert(\'SE GUARDO CON EXITO!\');'; echo 'window.location="altas.php";'; echo '</script>'; echo "<br>"; } } } echo "</form>"; ?> <br> </body> </html> Título: Re: problema con formulario para insertar informacion en base de datos Publicado por: s7evin en 24 Abril 2013, 17:48 pm Buenas tardes,
Mmm... a ver.. el código es un poco caótico y se puede pulir un poco jeje (no me malinterpretes, no lo critico, pero hay cosas que te las podrías ahorrar o hacerlas de forma más legible/ordenada). Seguramente es un error de SQL; estas filtrando/escapando los datos en algún sitio? podría venir de ahí el problema. En el insert: Código: mysql_query("INSERT INTO equipo (clave,articulo,cantidad, marca, modelo, numero_serie, color, especificaciones, numero_inventario, numero_equipo) Mete un 'or exit' / 'or die' (solo para debugar, cuando termines y funcione OK, elimínalo por si acaso..): Código: mysql_query("INSERT INTO equipo (clave,articulo,cantidad, marca, modelo, numero_serie, color, especificaciones, numero_inventario, numero_equipo) ojo con esta línea: Código: $fec=$_SESSIOn ["fecha"]; Debe ser $_SESSION, sino no te cogerá el valor PHP es CaseSensitive Y no sé, si no sigues sin ver el fallo.. facilítanos más datos a ver si lo encontrmos. Saludos! |