Ver Mensaje Individual
  #9 (permalink)  
Antiguo 30/04/2012, 15:39
Avatar de GatorV
GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: No me graba datos del formulario a la base de datos

Código PHP:
Ver original
  1. // mal:
  2. @$pregunta=$_POST[$rowPreg['cod_idpregunta']];
  3. @$respuesta=$_POST['respuesta'];
  4. // bien:
  5. $pregunta = $_POST['cod_pregunta'];
  6. $respuesta = $_POST['respuesta'];

No es bueno usar @ para suprimir errores, mejor comprueba que exista la variable y así puedes manejar errores:

Código PHP:
Ver original
  1. if ('post' == strtolower($_SERVER['REQUEST_METHOD'])) {
  2.         $pregunta = $_POST['cod_pregunta'];
  3.         $respuesta = $_POST['respuesta'];
  4.         $s="insert into respuestas(pregunta,respuesta) values('$pregunta','$respuesta')";
  5.         echo 'Your Data Inserted';
  6.         mysql_query($s) or die(mysql_error());
  7. }

Saludos.