Foros del Web » Programando para Internet » PHP »

Problema al insertar en db

Estas en el tema de Problema al insertar en db en el foro de PHP en Foros del Web. Hola, tengo este codigo: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código PHP: Ver original <?php $http = "blog" ; include ( "../includes/conexion.php" ) ; include ( "../includes/contador.php" ) ; ...
  #1 (permalink)  
Antiguo 24/07/2011, 18:50
Avatar de PabloPF  
Fecha de Ingreso: mayo-2011
Ubicación: Ciudadano de un lugar llamado mundo!
Mensajes: 137
Antigüedad: 12 años, 11 meses
Puntos: 5
Pregunta Problema al insertar en db

Hola, tengo este codigo:
Código PHP:
Ver original
  1. <?php
  2. $http="blog";
  3. include("../includes/conexion.php");
  4. include("../includes/contador.php");
  5. getBrowser();
  6. if($ip!="X.x.x.x"){
  7. echo '<meta http-equiv="Refresh" content="0;url=http://x.x.com">';
  8. }
  9. else{
  10.     if(isset($_POST['enviar']))//Vallidamos que el formulario fue enviado
  11. {
  12.     $_POST['title']=$title;
  13.     $_POST['date']=$date;
  14.     $_POST['content']=$content;
  15.     $_POST['mes']=$mes;
  16.  
  17. mysql_query("INSERT INTO db SET title='$title',mes='$mes',date='$date',content='$content'");
  18. }
  19. ?>
  20. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  21. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
  22. <head>
  23. <meta name="robots" content="NOINDEX ,NOFOLLOW ,NOARCHIVE" />
  24. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  25. <title>Añadir entradas al blog de manager de primera</title>
  26. </head><body><div style="text-align: center;">
  27. <form name="enviar" action="add" method="post" />
  28.         <input type='text' name='title' value="Título"  onfocus="if (this.value == 'Título') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Título';}" /><br /><br />
  29.  
  30.         <input type="text" name="mes" value="Mes"  onfocus="if (this.value == 'Mes') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Mes';}" /><br /><br />
  31.  
  32.  
  33.         <input type="text" name="date" value="Fecha"  onfocus="if (this.value == 'Fecha') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Fecha';}" /><br /><br />
  34.        
  35.                 <textarea name="content"></textarea><br /><br />
  36.                         <input type="submit" name="enviar" style="width:100px;" tabindex="6" value="add" />
  37.  
  38.     </form>
  39.    
  40.     </div>
  41. </body>
  42. </html>
  43. <?php }?>
Y el problema es que en la base de datos me aparecen los campos en blanco, ¿que está mal? gracias.
__________________
no hay justicia si la guerra esta justificada

Última edición por cvander; 31/07/2011 a las 15:53
  #2 (permalink)  
Antiguo 24/07/2011, 19:02
Avatar de solhdeck  
Fecha de Ingreso: junio-2011
Mensajes: 87
Antigüedad: 12 años, 10 meses
Puntos: 32
Respuesta: Problema al insertar en db

Las líneas 12 a 15 están mal estructuradas o.o
Código PHP:
$title=$_POST['title'];
$date=$_POST['date'];
$content=$_POST['content'];
$mes=$_POST['mes']; 
Tal y como lo tenías tú, lo que haces es borrar (o intentarlo) lo que recibes de post, ya que no declaras las variables mes, content, date ni title antes, por lo que están en blanco
  #3 (permalink)  
Antiguo 24/07/2011, 19:03
Avatar de PabloPF  
Fecha de Ingreso: mayo-2011
Ubicación: Ciudadano de un lugar llamado mundo!
Mensajes: 137
Antigüedad: 12 años, 11 meses
Puntos: 5
Respuesta: Problema al insertar en db

Cierto! muchas gracias!
__________________
no hay justicia si la guerra esta justificada

Etiquetas: html, mysql, formulario
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 11:23.