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
  • 0

[Ayuda]Problema con submit de formulario

TENGO ESTE CODIGO PERO NO FUNCIONA
1? 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
  • 0
  • 0Calificación
  • 1Seguidores
  • 237Visitas
  • 0Favoritos

11 comentarios

@syneto Hace más de 1 año
seria agradable que pusieras el codigo entre las etiquetas code.
@lugolu Hace más de 1 año
postea el código entre etiquetas code debidamente indentado, sino es ilegible
de paso agrega un poco más de información, llega a ejecutar el insert. te tira un error, qué hace?
@alisandro Hace más de 1 año
lugolu dijo:

postea el código entre etiquetas code debidamente indentado, sino es ilegible
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
@Js_Toni Hace más de 1 año
syneto dijo:

seria agradable que pusieras el codigo entre las etiquetas code.



creo que no le estas haciendo la action al form

asi lo tienes tu:
&lt;form name=myChoices&gt;

falta la action para el form

&lt;form name=&quot;myChoices&quot; action=&quot;taringa.php&quot; method=&quot;post&quot;&gt; o method GET

y en taringa.php tiene que estar funcionando tu php


$_POST
$_GET
@pichoncitotv Hace más de 1 año
Js_Toni dijo:

syneto dijo:

seria agradable que pusieras el codigo entre las etiquetas code.



creo que no le estas haciendo la action al form

asi lo tienes tu:
&lt;form name=myChoices&gt;

falta la action para el form

&lt;form name=&quot;myChoices&quot; action=&quot;taringa.php&quot; method=&quot;post&quot;&gt; 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.
@lugolu Hace más de 1 año
yedeon dijo:

sigo con este codigo y quiero hacer un if en &quot;insertar5.php&quot;

if (!empty($ciudad ))
{ $Sql=&quot;select * from orejas where nombre = '&quot;.$_POST[&quot;nombre&quot;].&quot;'&amp;&amp; ciudad = '&quot;.$_POST[&quot;ciudad&quot;].&quot;' &quot;;}
else { $Sql=&quot;select * from orejas where nombre = '&quot;.$_POST[&quot;nombre&quot;].&quot;' &quot;;}

si pongo $Sql=&quot;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
&quot;nombre&quot;



es and no &amp;&amp; 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
Tienes que ser miembro para responder en este tema