Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/09/2007, 09:14
Cesdeveloper
 
Fecha de Ingreso: septiembre-2007
Mensajes: 44
Antigüedad: 16 años, 7 meses
Puntos: 0
problemas con un script que crea un .txt

Saludos soy muy nuevo ene este foro y le motivo de este mensaje es que me ayuden en un humilde codigo que estoy haciendo aqui va:
-----------------------------------------index.php-------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Archivos en php</title>
<style type="text/css">

h2 {color: red; }
body {background-color: #3363CC; }
</style>
</head>
<body >
<h2 align = "center"> Creacion de archivos </h2>
<form action= "crear_archivo.php" method= "post">
<table align ="center" style="top:10px">

<tr>
<td>Nombre:</td>
<td><input type= "text" name="nombre"/></td>
</tr>
<tr>
<td>Direccion:</td>
<td><input type= "text" name="direccion"/></td>
</tr>
<tr>
<td> Jamon y queso</td> <td> <input type="checkbox" name="myCheck[]" value = "1"/></td>

</tr>
<tr>
<td>Cantidad:</td>
<td><input type= "text" size="2" maxlength="20" name="cantidad"/></td>

</tr>
<tr>
<td> Napolitana</td> <td><input type="checkbox" name="myCheck[]" value = "2"/></td>

</tr>

<tr>
<td>Cantidad:</td>
<td><input type= "text" size="2" maxlength="20" name="cantidad"/></td>

<tr>

<tr>

<td> Muzarella</td>
<td><input type="checkbox" name="myCheck[]" value = "3"/></td>
</tr>

<tr>
<td> Cantidad:</td>
<td><input type= "text" size="2" maxlength="20" name="cantidad"/></td>

</tr>

<tr >
<td ><input type="submit" name="submit" value="Enviar"/></td>
</tr>


</table>
</form>
</body>


</html>
-------------------------------------crear_archivo.php--------------------------------------------------------------------
<?php
$nombre = $_POST["nombre"];
$dir = $_POST["direccion"];
$check=$_POST["myCheck"];
$cant= $_POST["cantidad"];
$singleVar =0;

?>
<html>
<head>
<title>Archivo creado</title>
</head>
<body>
<?php
if(isset($_POST['submit']))
{
$ar=fopen("pedidos.txt","a+") or die("Problemas en la creacion");
fputs($ar,$nombre);
fputs($ar,"\r\n");
fputs($ar,$dir);
fputs($ar,"\r\n");
if(isset($check))
{
foreach($check as $singleVar)
{
if ($singleVar == 1)
{
fputs($ar,"Jamon y queso:");
fputs($ar,"\r\n");
fputs($ar, "Cantidad:");
fputs($ar,"\r\n");
fputs($ar,$cant);
}

if ($singleVar == 2)
{
fputs($ar,"Napolitana:");
fputs($ar,"\r\n");
fputs($ar, "Cantidad:");
fputs($ar,"\r\n");
fputs($ar,$cant);
}


if ($singleVar == 3)
{
fputs($ar,"Muzarella:");
fputs($ar,"\r\n");
fputs($ar, "Cantidad:");
fputs($ar,"\r\n");
fputs($ar,$cant);
}


}
}
else
{
echo "No puedo seleccionar los checkboxes";
}
fputs($ar,"\r\n");

fputs($ar,"\r\n");
fputs($ar,".....................................") ;
fputs($ar,"\r\n");

}

fclose($ar);
echo "Los datos se cargaron correctamente.";
?>
</body>
</html>
---------------------------------------------------------------------------------------------------------
EL programita hace unos pedidos (de una pizzeria)seleccionando de unos chckboxes y anotando el pedido en un inputtext y los guarda en un .txt,en este caso lo hace pero solo me carga los del ultimo chckbox(muzarrella) como hago para cargar los demas. Eso es todo disculpen lo largo pero es mejor explicar la duda con el codigo. Hasta luego.