Foros del Web » Programando para Internet » PHP »

no agrega nada a mi BD

Estas en el tema de no agrega nada a mi BD en el foro de PHP en Foros del Web. holas... estoy de vuelta aprendiendo mas sobre php =) ahora tengo un pequeño problema. hice unos archivos en php y tmb una bd trato de ...
  #1 (permalink)  
Antiguo 07/01/2010, 21:50
Avatar de shadowjhac  
Fecha de Ingreso: diciembre-2009
Ubicación: Peru
Mensajes: 27
Antigüedad: 14 años, 4 meses
Puntos: 0
no agrega nada a mi BD

holas... estoy de vuelta aprendiendo mas sobre php =)

ahora tengo un pequeño problema.

hice unos archivos en php y tmb una bd trato de agregar registros pero todo m agrega en blanco, no se exactamente cual es el error, podrian ayudarme por favor??

aqui esta el codigo
seleccionar.php
Código PHP:
<!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>SELECCIONE RUTA</title>
<
style type="text/css">
<!--
body {
    
background-color#0033FF;
}
-->
</
style></head>

<
body>
<
div align="center">
  <
table width="1006" height="209" border="0" align="center">
    <
tr>
      <
th colspan="5" bordercolor="#000000" scope="col"><object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,0,0" width="512" height="150">
          <
param name="src" value="imagen/TRANSPORTE.swf" />
          <
embed src="imagen/TRANSPORTE.swf" pluginspage="http://www.macromedia.com/shockwave/download/" width="512" height="150"></embed>
        </
object></th>
    </
tr>
    <
tr>
      <
th colspan="5" bordercolor="#000000">        <h1>SISTEMA DE CONTROL DE PASAJES </h1></th>
    </
tr>
    <
tr>
      <
th width="162" bordercolor="#000000">        <h3><strong><a href="index.php">INICIO</a></strong></h3></th>
      <
th width="252" bordercolor="#000000">        <h3><strong><a href="seleccionar.php">SELECCIONAR SERVICIO</a> </strong></h3></th>
      <
th width="179" bordercolor="#000000">        <h3><strong><a href="listar.php">LISTAR</a></strong></h3></th>
      <
th width="204" bordercolor="#000000">        <h3><strong><a href="borrar.php">BORRAR</a></strong></h3></th>
      <
th width="187" bordercolor="#000000">        <h3><strong><a href="contactenos.php">CONTACTENOS</a></strong></h3></th>
    </
tr>
    <
tr>
      <
td colspan="5"><div align="center">
        <
p>&nbsp;</p>
        <
p>&nbsp;</p>
        <
table width="1052" height="94" border="1" align="center">
  <
tr>
    <
td width="160" height="50" bgcolor="#00CCFF"><div align="center"><strong>FECHA DE VIAJE </strong></div></td>
    <
td width="148" bgcolor="#00CCFF"><div align="center"><strong>RUTA</strong></div></td>
    <
td width="144" bgcolor="#00CCFF"><div align="center"><strong>AGENCIA</strong></div></td>
    <
td width="144" bgcolor="#00CCFF"><div align="center"><strong>SALIDA</strong></div></td>
    <
td width="150" bgcolor="#00CCFF"><div align="center"><strong>Nro ASIENTO </strong></div></td>
    <
td width="146" bgcolor="#00CCFF"><div align="center"><strong>Nro PISO </strong></div></td>
    <
td width="257" bgcolor="#00CCFF"><div align="center"><strong>COSTO S/. </strong></div></td>
  </
tr>
  <
tr>

    <
td height="36"><div align="center">
            <
input type="date" name="fecha" />
 </
div></td>
   <
td>
      <
p align="center">
        <
input type="text" name="ruta" />
    <
td><p align="center">
  <
input type="text" name="agencia" />
    <
td>
     <
p align="center">
        <
input type="text" name="salida" />
    <
td> <div align="center">
      <
input type="text" name="asiento" />   
    </
div>
    <
td> <div align="center">
      <
input type="text" name="piso" />   
    </
div>
    <
td>
      <
p align="center">
        <
input type="text" name="costo" />
        </
tr>
</
table>
<
div align="center"><br>
<
form action="seleccionar2.php" method="post">

  <
input name="submit" type="submit" value="A&ntilde;adir" />
  </
form>
</
div>
  
      <
div align="center"></div>      <div align="center"></div></td>
    </
tr>
  </
table>
  
</
div>
</
body>
</
html
y aqui el php al cual hizo el llamado seleccionar2.php

Código PHP:
<!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>SELECCIONE RUTA</title>
<style type="text/css">
<!--
body {
    background-color: #0033FF;
}
-->
</style></head>

<body>
<div align="center">
  <table width="1006" height="209" border="0" align="center">
    <tr>
      <th colspan="5" bordercolor="#000000" scope="col"><object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,0,0" width="512" height="150">
          <param name="src" value="imagen/TRANSPORTE.swf" />
          <embed src="imagen/TRANSPORTE.swf" pluginspage="http://www.macromedia.com/shockwave/download/" width="512" height="150"></embed>
        </object></th>
    </tr>
    <tr>
      <th colspan="5" bordercolor="#000000">        <h1>SISTEMA DE CONTROL DE PASAJES </h1></th>
    </tr>
    <tr>
      <th width="162" bordercolor="#000000">        <h3><strong><a href="index.php">INICIO</a></strong></h3></th>
      <th width="252" bordercolor="#000000">        <h3><strong><a href="seleccionar.php">SELECCIONAR SERVICIO</a> </strong></h3></th>
      <th width="179" bordercolor="#000000">        <h3><strong><a href="listar.php">LISTAR</a></strong></h3></th>
      <th width="204" bordercolor="#000000">        <h3><strong><a href="borrar.php">BORRAR</a></strong></h3></th>
      <th width="187" bordercolor="#000000">        <h3><strong><a href="contactenos.php">CONTACTENOS</a></strong></h3></th>
    </tr>
    <tr>
      <td colspan="5"><div align="center">
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <?php
$conexion
=mysql_connect("localhost","root","admin") or die("Problemas en
la conexion"
);
mysql_select_db("sistema",$conexion) or die("Problemas en la seleccion
de la base de datos"
);
mysql_query("insert into control(fecha, ruta, agencia, salida, asiento, piso, costo) values
('$_POST[fecha]','$_POST[ruta]','$_POST[agencia]','$_POST[salida]','$_POST[asiento]''$_POST[piso]''$_POST[costo]')"
,
$conexion) or die("Problemas en el select".mysql_error());
mysql_close($conexion);
echo 
"Los datos han sido introducidos en la base de datos";
?>
        <div align="center"><br>

</div>
      </div>        <div align="center"></div>        <div align="center"></div>        <div align="center"></div>        <div align="center"></div>
      <div align="center"></div>      <div align="center"></div></td>
    </tr>
  </table>
  
</div>
</body>
</html>
PD. mi base de datos se llama SISTEMA, mi tabla CONTROL
mis campos son:

id, fecha, ruta, agencia, salida, asiento, piso, costo

todos son varchar (30) excepto id ="INT"(11) y fecha = "DATE" (11)

q puede estar mal? una ayudita para poder seguir aprendiendo por favor...
  #2 (permalink)  
Antiguo 07/01/2010, 22:14
 
Fecha de Ingreso: enero-2008
Ubicación: /España/Galicia
Mensajes: 928
Antigüedad: 16 años, 3 meses
Puntos: 21
Respuesta: no agrega nada a mi BD

$_POST[fecha]

es asi

$_POST['fecha']

y pones insert into control(

deja un espacio
  #3 (permalink)  
Antiguo 07/01/2010, 22:24
 
Fecha de Ingreso: agosto-2009
Ubicación: Al fondo a la derecha
Mensajes: 308
Antigüedad: 14 años, 8 meses
Puntos: 6
Respuesta: no agrega nada a mi BD

Código PHP:
mysql_query("insert into control(fecha, ruta, agencia, salida, asiento, piso, costo) values 
('$_POST[fecha]','$_POST[ruta]','$_POST[agencia]','$_POST[salida]','$_POST[asiento]''$_POST[piso]''$_POST[costo]')"

$conexion) or die("Problemas en el select".mysql_error()); 
Las últimas inserciones no están separadas por comas.

Si el $_POST se encuentra dentro de comillas simples creo que no es recomendable ponerle las comillas al $_POST

al igual que en un echo...

Fijate lo de las comas debería quedar así:
Código PHP:
mysql_query("insert into control(fecha, ruta, agencia, salida, asiento, piso, costo) values 
('$_POST[fecha]','$_POST[ruta]','$_POST[agencia]','$_POST[salida]','$_POST[asiento]','$_POST[piso]','$_POST[costo]')"

$conexion) or die("Problemas en el select".mysql_error()); 
PD: no es seguro realizar consultas sql con $_POST en estado puro, tratá de filtrarla antes de manipularla.
__________________
Abre tu mente: Index no signigica index, significa índice
  #4 (permalink)  
Antiguo 08/01/2010, 05:49
Avatar de DooBie  
Fecha de Ingreso: septiembre-2004
Mensajes: 1.101
Antigüedad: 19 años, 7 meses
Puntos: 71
Respuesta: no agrega nada a mi BD

El problema lo tienes en el codigo html, no tienes bien estructurado el formulario, la etiqueta <form ....> esta despues de todos los campos, solo encapsulas el boton!

asi el formulario, no reconoce el resto de campos.

debes poner la etiqueta:
<form action="seleccionar2.php" method="post">
ANTES del <table...>
y la etiqueta </form>
DESPUES del </table>

Prueba, y nos cuentas.

Etiquetas: bd
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:01.