Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/03/2016, 13:20
calel_leon
 
Fecha de Ingreso: febrero-2016
Mensajes: 48
Antigüedad: 8 años, 2 meses
Puntos: 0
Problemas con guardar datos en BD

Uso el siguiente código para obtener variables provenientes de un formulario

En el código, transformo variables con nombres provenientes en formulario, en sus id correspondiente, ya que de esa forma son guardador en la tabla.

Código PHP:
<?php
require_once("conexion.php");

$activ $_POST["activ"];
$sect $_POST["sect"];
$cuart $_POST["cuart"];
$fechini $_POST["fechainicio"];
$cost $_POST["costo"];
$traba $_POST["trabajadores"];
$prod $_POST["produc"];
$comen $_POST["comentario"];
$usuar "1";
?>

<!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=utf-8" />
<title>RUTA Control</title>
<link href="css/estilos_basicos.css" rel="stylesheet" type="text/css" />
<link href="css/textos.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div id="principal">
  <div id="encabezado"><img src="imagenes/logo ruta.png" width="900" height="148" alt="logo" /></div>
  <div id="menu"><img src="imagenes/boton_00.gif" width="225" height="46" alt="oo" /><img src="imagenes/boton_00.gif" width="225" height="46" /><img src="imagenes/boton_00.gif" width="225" height="46" /><img src="imagenes/boton_00.gif" width="225" height="46" /></div>
  <div id="contenido">
      <div class="texto">
        
          <h1> Nueva Orden de Trabajo</h1>
              <?php            
                        
            $sql1
=mysql_query("SELECT actividad_id FROM actividad where actividad = '$activ'",$con) or die('Query failed: ' mysql_error());
            while(
$row mysql_fetch_array($sql1))
            {
                if(
$row['actividad'] = $activ)
                    
$id1 $row['actividad_id'];
                    
//$nombre = $row['actividad'];    
            
}
            
                    
            
$sql2=mysql_query("SELECT sector_id FROM sector where nombre = '$sect'",$con) or die('Query failed: ' mysql_error());
            while(
$row mysql_fetch_array($sql2))
            {
                if(
$row['nombre'] = $sect)
                    
$id2 $row['sector_id'];
                    
//$nombre = $row['actividad'];    
            
}
            
            
$sql3=mysql_query("SELECT cuartel_id FROM cuartel where nombre = '$cuart'",$con) or die('Query failed: ' mysql_error());
            while(
$row mysql_fetch_array($sql3))
            {
                if(
$row['nombre'] = $sect)
                    
$id3 $row['cuartel_id'];
                    
//$nombre = $row['actividad'];    
            
}
            
            
$sql4=mysql_query("SELECT producto_id FROM producto where nombre = '$prod'",$con) or die('Query failed: ' mysql_error());
            while(
$row mysql_fetch_array($sql4))
            {
                if(
$row['nombre'] = $sect)
                    
$id4 $row['producto_id'];
                    
//$nombre = $row['actividad'];    
            
}            
            
            
$estado "pendiente";
            
              if(isset(
$_POST['activ']) && !empty($_POST['activ']))
            {
    
            
mysql_query("INSERT INTO orden VALUES('null','$id1','$id2','$fechini','$comen','$cost','$traba','now()','$usuar','$id4','$id3,$estado)");
    
            echo 
"Datos del Orden de Trabajo ingresados correctamente.";
            }
            else
            {
                echo 
"Faltan datos en formulario";
            }

            
?>
          <p><a href="orden.php">Volver</a> </p>
      </div>
   
  </div>
  <div id="pie">Ruta Control</div>
</div>
</body>
</html>
el problema radica, que al guardar la funcion envia el mensaje de exito, indicando que los datos fueron guardados, pero no quedan registrados.