Ver Mensaje Individual
  #5 (permalink)  
Antiguo 17/03/2008, 09:32
Avatar de T4ke0veR
T4ke0veR
 
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 9 meses
Puntos: 28
Re: Enviando campos vacios de form a DB

Código PHP:
<?php require_once('Connections/flamuko.php'); ?>
<?php
include_once("fckeditor/fckeditor.php") ;
?>
<?php
function GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

$ediciondir'../imgprod/';  
$uploaddir=$ediciondir;
if (!
is_dir($ediciondir)) {     mkdir($uploaddir0777);    }
move_uploaded_file($_FILES['imagen']['tmp_name'], $uploaddir $_FILES['imagen']['name']);    
$filename $_FILES['imagen']['name'];


$insertSQL sprintf("INSERT INTO productos (id_cat, id_sub, id_lin, nombre, codigo, descripcion, imagen) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['id_cat'], "int"),
                       
GetSQLValueString($_POST['id_sub'], "int"),
                       
GetSQLValueString($_POST['id_lin'], "int"),
                       
GetSQLValueString($_POST['nombre'], "text"),
                       
GetSQLValueString($_POST['codigo'], "text"),
                       
GetSQLValueString($_POST['descripcion'], "text"),
                       
GetSQLValueString($filename"text"));

  
mysql_select_db($database_flamuko$flamuko);
  
$Result1 mysql_query($insertSQL$flamuko) or die(mysql_error());

  
$insertGoTo "listado_prod.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}

mysql_select_db($database_flamuko$flamuko);
$query_Recordset1 "SELECT * FROM categoria";
$Recordset1 mysql_query($query_Recordset1$flamuko) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);

mysql_select_db($database_flamuko$flamuko);
$query_Recordset2 "SELECT * FROM subcategoria";
$Recordset2 mysql_query($query_Recordset2$flamuko) or die(mysql_error());
$row_Recordset2 mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 mysql_num_rows($Recordset2);

mysql_select_db($database_flamuko$flamuko);
$query_Recordset3 "SELECT * FROM linea";
$Recordset3 mysql_query($query_Recordset3$flamuko) or die(mysql_error());
$row_Recordset3 mysql_fetch_assoc($Recordset3);
$totalRows_Recordset3 mysql_num_rows($Recordset3);

?>
la idea es q cuando yo no quiera enviar el codigo del producto no lo ingrese y listo!!!!
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...