Jump to content

Recommended Posts

Hi.

I´m learning PHP and trying to develope a Form using arrays.

In this case I want to show 2 lists from an arrays for themselves, but I´m having problems, and don´t know how to solve the error that I receive.

The error is something related with undefined variables or something like that.

Please, can you help me???

 

Thanks,

 

My code is the following:

 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>inicio</title>
</head>

<?php
// Provincias de España

$provincias = array("A Coruña", "Madrid","A Coruña", "Álava", "Albacete", "Alicante", "Almeria", "Asturias", "Ávila", "Badajoz", "Baleares", "Barcelona",
"Burgos", "Cáceres", "Cádiz", "Cantabria", "Castellón", "Ceuta", "Ciudad Real", "Córdoba",
"Cuenca", "Girona", "Granada", "Guadalajara", "Guipúzcoa", "Gran Canaria", "Huelva",
"Huesca", "Jaén", "La Rioja", "Las Palmas", "León", "Lleida", "Lugo", "Madrid",
"Málaga", "Melilla", "Murcia", "Navarra", "Ourense", "Palencia", "Pontevedra",
"Salamanca", "Tenerife", "Segovia", "Sevilla", "Soria", "Tarragona",
"Teruel", "Toledo", "Valencia", "Valladolid", "Vizcaya", "Zamora", "Zaragoza" );

// localidades de Madrid


	  
$madrid = array ( "Alcalá de Henares", "Alcobendas", "Alcorcón", "Aldea del Fresno", "Alpedrete", "Aranjuez", "Arganda del Rey",
"Arroyomolinos", "Alcalá de Henares", "Alcobendas", "Alcorcón", "Aldea del Fresno", "Alpedrete", "Aranjuez", "Arganda del Rey",
"Arroyomolinos", "Batres", "El Berrueco", "Boadilla del Monte", "El Boalo", "Buitrago del Lozoya", "La Cabrera", "Cadalso de los Vidrios",
"Cenicientos", "Chinchón", "Collado Mediano", "Collado Villalba", "Colmenar de Oreja", "Colmenar Viejo", "Coslada", "El Escorial",
"Fresnedillas de la Oliva", "Fuenlabrada", "Fuente el Saz de Jarama", "Fuentidueña de Tajo", "Galapagar", "Getafe", "Guadarrama",
"Humanes de Madrid", "Leganés", "Loeches", "Madrid", "Majadahonda", "Manzanares el Real", "Mejorada del Campo", "Móstoles",
"Navacerrada", "Navalagamella", "Navalcarnero", "Nuevo Baztán", "Parla", "Patones", "Pinto", "Pozuelo de Alarcón",
"Puebla de la Sierra", "Puentes Viejas", "Rascafría", "Robledo de Chavela", "Las Rozas de Madrid", "San Fernando de Henares",
"San Lorenzo de El Escorial", "San Martín de la Vega", "San Martín de Valdeiglesias", "San Sebastián de los Reyes",
"Santa María de la Alameda", "Santorcaz", "Talamanca de Jarama", "Torrejón de Ardoz", "Torrejón de Velasco", "Torrelaguna",
"Torrelodones", "Valdemaqueda", "Valdemorillo", "Valdemoro", "Villaconejos", "Villanueva de la Cañada", "Villar del Olmo",
"Villarejo de Salvanés" );
?>

<body bgcolor="#FFFFFF">

<center>

<form METHOD="POST" action="">

<table border="1">
<tr>
<td>PROVINCIA: <?php
$cuenta = array_count_values ($provincias);
$i = 0;
reset($provincias);
while($i <= $cuenta){
echo "<option value='".$provincias[$i]."'>".$provincias[$i]."</option>";
$i++;
}  
?></td>

<td>LOCALIDAD: <?php 
$cuenta2 = array_count_values ($madrid);
$ix = 0;
reset($madrid);
while($ix <= $cuenta2){
echo "<option value='".$madrid[$ix]."'>".$madrid[$ix]."</option>";
$ix++;
} 
?></td>
</tr>
</table>
<br>
<br>

<input type="submit" value="enviar">

</center>

</form>

</body>
</html>

Hi. Now the code is looking good and work fine...

 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>inicio</title>
</head>

<?php
// Provincias de España

$provincias = array("A Coruña", "Madrid","A Coruña", "Álava", "Albacete", "Alicante", "Almeria", "Asturias", "Ávila", "Badajoz", "Baleares", "Barcelona",
"Burgos", "Cáceres", "Cádiz", "Cantabria", "Castellón", "Ceuta", "Ciudad Real", "Córdoba",
"Cuenca", "Girona", "Granada", "Guadalajara", "Guipúzcoa", "Gran Canaria", "Huelva",
"Huesca", "Jaén", "La Rioja", "Las Palmas", "León", "Lleida", "Lugo", "Madrid",
"Málaga", "Melilla", "Murcia", "Navarra", "Ourense", "Palencia", "Pontevedra",
"Salamanca", "Tenerife", "Segovia", "Sevilla", "Soria", "Tarragona",
"Teruel", "Toledo", "Valencia", "Valladolid", "Vizcaya", "Zamora", "Zaragoza" );

// localidades de Madrid


	  
$madrid = array ( "Alcalá de Henares", "Alcobendas", "Alcorcón", "Aldea del Fresno", "Alpedrete", "Aranjuez", "Arganda del Rey",
"Arroyomolinos", "Alcalá de Henares", "Alcobendas", "Alcorcón", "Aldea del Fresno", "Alpedrete", "Aranjuez", "Arganda del Rey",
"Arroyomolinos", "Batres", "El Berrueco", "Boadilla del Monte", "El Boalo", "Buitrago del Lozoya", "La Cabrera", "Cadalso de los Vidrios",
"Cenicientos", "Chinchón", "Collado Mediano", "Collado Villalba", "Colmenar de Oreja", "Colmenar Viejo", "Coslada", "El Escorial",
"Fresnedillas de la Oliva", "Fuenlabrada", "Fuente el Saz de Jarama", "Fuentidueña de Tajo", "Galapagar", "Getafe", "Guadarrama",
"Humanes de Madrid", "Leganés", "Loeches", "Madrid", "Majadahonda", "Manzanares el Real", "Mejorada del Campo", "Móstoles",
"Navacerrada", "Navalagamella", "Navalcarnero", "Nuevo Baztán", "Parla", "Patones", "Pinto", "Pozuelo de Alarcón",
"Puebla de la Sierra", "Puentes Viejas", "Rascafría", "Robledo de Chavela", "Las Rozas de Madrid", "San Fernando de Henares",
"San Lorenzo de El Escorial", "San Martín de la Vega", "San Martín de Valdeiglesias", "San Sebastián de los Reyes",
"Santa María de la Alameda", "Santorcaz", "Talamanca de Jarama", "Torrejón de Ardoz", "Torrejón de Velasco", "Torrelaguna",
"Torrelodones", "Valdemaqueda", "Valdemorillo", "Valdemoro", "Villaconejos", "Villanueva de la Cañada", "Villar del Olmo",
"Villarejo de Salvanés" );
?>

<body bgcolor="#FFFFFF">

<center>

<form METHOD="POST" action="busca.php" name=frminsertar>

<table border="1">
<tr>
<td>PROVINCIA:<br>
<select name=provincia>

<?php
$cuenta = array_count_values ($provincias);
$i = 0;
reset($provincias);


foreach ($provincias as $value=>$prov)
{

echo "<option  value='".$provincias[$i]."'>".$provincias[$i]."</option>";
$i++;
}

?>

</td>


<td>LOCALIDAD: <br>
<select name=localidad>

<?php 
$cuenta2 = array_count_values ($madrid);
$ix = 0;
reset($madrid);

foreach ($madrid as $value=>$loc )
{
echo "<option value='".$madrid[$ix]."'>".$madrid[$ix]."</option>";
$ix++;
} 
?>

</select>


</td>
</tr>
</table>
<br>
<br>

<input  name="submit" type="submit" value="enviar">

</center>

</form>

</body>
</html>

 

And Now, Im trying to receive the results of the form in another php file, BUT, I don´t receive anything. I don´t know how to post the results to use them in another file...

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
</head>

<body>

<?php
$laprov=$_POST["$provincias"];


echo "valores recibidos: $laprov <br>";
?>


</body>
</html>

 

Please, can you help me to see what I´m receiving from the first form?????

Thanks a lot for your help.

Hi,

not, it doesn´t work.

I receive: Notice: Use of undefined constant provincias - assumed 'provincias' in C:\wamp\www\busca.php on line 13, and Notice: Undefined index: provincias in C:\wamp\www\busca.php on line 13.

 

the file busca.php is the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
</head>

<body>

<?php


echo  $_POST[provincias];
?>


</body>
</html>

 

thanks.

regards, and thankyou for your help. I really apreciate it.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.