Comunidad oficial de diseñadores web, web developers y Webmasters. Aqui podemos tratar temas actuales sobre diseño y tecnología. Podemos compartir y actualizarnos. Flash, PHP, ASP, Java, HTML, CSS, MySQL, CMS, etc. Unite YA y lee los Sticky
Ver más- 17,191 Miembros
- 12,944 Temas
- 4,966 Seguidores
[Ayuda]Problema con submit de formulario
TENGO ESTE CODIGO PERO NO FUNCIONA1? POR QUE AL HACER CLIC EN EL BOTON SUBMIT NO VA HACIA EL ARCHIVO .PHP
2? QUE NECESITO CAMBIAR PARA QUE INSERTE LAS SELECCIONES EN LA BASE DE DATOS?
<html>
<TITLE>insertar5.html</TITLE>
<title>Listas desplegables dependientes</title>
<BODY style="font-family: Verdana">
<p align="center"><b>Listas desplegables dependientes 5</b></p>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var arrItems1 = new Array();
var arrItemsGrp1 = new Array();
arrItems1[1] = "a1"; arrItemsGrp1[1] = 1;
arrItems1[2] = "a2"; arrItemsGrp1[2] = 1;
arrItems1[3] = "a3"; arrItemsGrp1[3] = 1;
arrItems1[4] = "a4"; arrItemsGrp1[4] = 1;
arrItems1[5] = "b1"; arrItemsGrp1[5] = 2;
arrItems1[6] = "b2"; arrItemsGrp1[6] = 2;
arrItems1[7] = "c1"; arrItemsGrp1[7] = 3;
arrItems1[8] = "c2"; arrItemsGrp1[8] = 3;
var arrItems2 = new Array();
var arrItemsGrp2 = new Array();
arrItems2[1] = "aa1"; arrItemsGrp2[1] = 1;
arrItems2[2] = "aa2"; arrItemsGrp2[2] = 2;
arrItems2[3] = "aa3"; arrItemsGrp2[3] = 3;
arrItems2[4] = "aa4"; arrItemsGrp2[4] = 4;
arrItems2[5] = "bb1.1"; arrItemsGrp2[5] = 5;
arrItems2[6] = "bb1.2"; arrItemsGrp2[6] = 5;
arrItems2[7] = "bb2.1"; arrItemsGrp2[7] = 6;
arrItems2[8] = "cc1.1"; arrItemsGrp2[8] = 7;
arrItems2[9] = "cc1.2"; arrItemsGrp2[9] = 7;
arrItems2[10] = "cc2.1"; arrItemsGrp2[10] = 8;
arrItems2[11] = "cc3.1"; arrItemsGrp2[11] = 9;
function selectChange(control, controlToPopulate, ItemArray, GroupArray)
{
var myEle ;
var x ;
// Empty the second drop down box of any choices
for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
if (control.name == "firstChoice") {
// Empty the third drop down box of any choices
for (var q=myChoices.thirdChoice.options.length;q>=0;q--) myChoices.thirdChoice.options[q] = null; }
// ADD Default Choice - in case there are no values
myEle = document.createElement("option") ;
myEle.value = 0 ;
myEle.text = "[Selecciona]" ;
controlToPopulate.add(myEle) ;
// Now loop through the array of individual items
// Any containing the same child id are added to
// the second dropdown box
for ( x = 0 ; x < ItemArray.length ; x++ )
{
if ( GroupArray[x] == control.value )
{
myEle = document.createElement("option") ;
myEle.value = x ;
myEle.text = ItemArray[x] ;
controlToPopulate.add(myEle) ;
}
}
}
// End -->
</script>
</HEAD>
<BODY style="font-family: Verdana">
<form name=myChoices>
<table align="center">
<tr>
<td>
<SELECT id=firstChoice name="firstChoice" onchange="selectChange(this, myChoices.secondChoice,
arrItems1,arrItemsGrp1);">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
</select> </br>
</SELECT>
</TD><TD>
<SELECT id=secondChoice name=secondChoice onchange="selectChange(this, myChoices.thirdChoice, arrItems2,
arrItemsGrp2);">
</SELECT>
<SELECT id=thirdChoice name=thirdChoice>
</TD>
</TR>
</TABLE>
<form action="insertar5.php" method="GET" >
<INPUT TYPE="SUBMIT" value="insertar5">
</SELECT>
</form>
</html>
<?
$con = mysql_connect("**************");
mysql_select_db("*********", $con);
if (!$con) { die('Could not connect: ' . mysql_error()); }
$sql="INSERT INTO orejas (a,b,c)
VALUES('$_POST[firstChoice]','$_POST[secondChoice]','$_POST[thirdChoice]')";
if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "1 record added";
mysql_close($con);
?>
lo que busco es un formulario que al realizar selecciones de 3 campos se inserte en mi base de datos
- 0Calificación
- 1Seguidores
- 237Visitas
- 0Favoritos
Global
Argentina
Chile
Colombia
España
México
Perú
Uruguay
Venezuela
11 comentarios
de paso agrega un poco más de información, llega a ejecutar el insert. te tira un error, qué hace?
y por favor, no escribas en mayúsculas
creo que no le estas haciendo la action al form
asi lo tienes tu:
<form name=myChoices>
falta la action para el form
<form name="myChoices" action="taringa.php" method="post"> o method GET
y en taringa.php tiene que estar funcionando tu php
$_POST
$_GET
Si no se establece un action en la etiqueta form, se toma al mismo archivo como action, así que ese no sería el problema.
$con = mysql_connect("**************"
mysql_select_db("*********", $con);
solo en mi user, host , pass y base de datos esta con ********** los demas es lo que tengo ( igual )
el codigo php lo teno en "insertar5.php"
y el codigo html esta en "insertar5.html"
tengo 3 listas deplegables que se llaman : firstChoice secondChoice thirdChoice
no entiendo a que se refieren con :
postea el código entre etiquetas code debidamente indentado ¡¡¡¡
el codigo html genera son 3 listbox o listas en las que escogo las opciones
al darle click al boton la pagina se refresca o actualiza y se borra lo seleccionado pero no cambia de pagina , me imagino que es por el onchange , pero no se como debe estar ?
o tampoco inserta los datos en la base de datos pues no aparece : "1 record added"; el mensaje de insertar5.php al ser exitoso
¡ Muchas gracias ,
<form name="myChoices" action="taringa.php" method="post"> o method GET
if (!empty($ciudad ))
{ $Sql="select * from orejas where nombre = '".$_POST["nombre"]."'&& ciudad = '".$_POST["ciudad"]."' ";}
else { $Sql="select * from orejas where nombre = '".$_POST["nombre"]."' ";}
si pongo $Sql="select * from .... uno ala vez funcionan
pero este if no me funciona el filtro de ciudad ? en los dos me filtra o selecciona solo por la variable
"nombre"
es and no && en sql
lo de code es poner el código entre etiquetas code en vez de quote para que no reemplaze código por caritas
lo de indentar es el código acomodado con tabulaciones y espacios que lo hace más entendible
ya funcionó agregando $_POST[" al IF
if (!empty($_POST["ciudad"]))
Por que me guarda la imagen en mi host sin renombrarla con el nuevo nombre "nomm"
<?php
$ruta= "imagenes/".$_FILES['fichero']['name'];
if (isset($_POST['submit'])) {
if(is_uploaded_file($_FILES['fichero']['tmp_name'])) { // verifica haya sido cargado el archivo
move_uploaded_file($_FILES['fichero']['tmp_name'], $ruta);
echo "<b>Upload exitoso!. Datos:</b><br>";
echo "Nombre: <i><a href="".$_FILES['fichero']['name']."">".$_FILES['fichero']['name']."</a></i><br>";
echo "Tipo MIME: <i>".$_FILES['fichero']['type']."</i><br>";
echo "Peso: <i>".$_FILES['fichero']['size']." bytes</i><br>";
echo "<br><hr><br>";
}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data">
nomm: <input name="nomm" type="text">
Archivo: <input name="fichero" type="file">
<input name="submit" type="submit" value="Upload!">
</form>