Ver Mensaje Individual
  #4 (permalink)  
Antiguo 05/05/2008, 21:10
Avatar de Capimaster
Capimaster
 
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Re: Campo vacio inserte valor por defecto

Fijate que me suena logico lo que me propusiste pero no me funciono... me sigue mandando el campo en blanco.. te paso mi codigo para ke le eches un ojo...

Código PHP:
<?php require_once('../Connections/portadas.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  
session_start();
}

// ** Logout the current user. **
$logoutAction $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset(
$_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  
$logoutAction .="&"htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  
//to fully log out a visitor we need to clear the session varialbles
  
$_SESSION['MM_Username'] = NULL;
  
$_SESSION['MM_UserGroup'] = NULL;
  
$_SESSION['PrevUrl'] = NULL;
  unset(
$_SESSION['MM_Username']);
  unset(
$_SESSION['MM_UserGroup']);
  unset(
$_SESSION['PrevUrl']);
    
  
$logoutGoTo "/noticias/index.php";
  if (
$logoutGoTo) {
    
header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  
session_start();
}
$MM_authorizedUsers "";
$MM_donotCheckaccess "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers$strGroups$UserName$UserGroup) { 
  
// For security, start by assuming the visitor is NOT authorized. 
  
$isValid False

  
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  
if (!empty($UserName)) { 
    
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    
$arrUsers Explode(","$strUsers); 
    
$arrGroups Explode(","$strGroups); 
    if (
in_array($UserName$arrUsers)) { 
      
$isValid true
    } 
    
// Or, you may restrict access to only certain users based on their username. 
    
if (in_array($UserGroup$arrGroups)) { 
      
$isValid true
    } 
    if ((
$strUsers == "") && true) { 
      
$isValid true
    } 
  } 
  return 
$isValid
}

$MM_restrictGoTo "/index2.php";
if (!((isset(
$_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers$_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  
$MM_qsChar "?";
  
$MM_referrer $_SERVER['PHP_SELF'];
  if (
strpos($MM_restrictGoTo"?")) $MM_qsChar "&";
  if (isset(
$QUERY_STRING) && strlen($QUERY_STRING) > 0
  
$MM_referrer .= "?" $QUERY_STRING;
  
$MM_restrictGoTo $MM_restrictGoTo$MM_qsChar "accesscheck=" urlencode($MM_referrer);
  
header("Location: "$MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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")) {
  
$insertSQL sprintf("INSERT INTO noticias (titulo, imagen, ruta, resumen, contenido) VALUES (%s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['titulo'], "text"),
                       
GetSQLValueString($_POST['imagen'], "text"),
                       
GetSQLValueString($_POST['ruta'], "text"),
                       
GetSQLValueString($_POST['resumen'], "text"),
                       
GetSQLValueString($_POST['contenido'], "text"));

  
mysql_select_db($database_portadas$portadas);
  
$Result1 mysql_query($insertSQL$portadas) or die(mysql_error());
}

mysql_select_db($database_portadas$portadas);
$query_ultimas "SELECT * FROM noticias ORDER BY id DESC";
$ultimas mysql_query($query_ultimas$portadas) or die(mysql_error());
$row_ultimas mysql_fetch_assoc($ultimas);
$totalRows_ultimas mysql_num_rows($ultimas);
?><!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>Noticiero elcapitolio.net</title>
<style type="text/css">
<!--
body {
    background-color: #EEEEEE;
}
body,td,th {
    font-family: Segoe UI, Arial, Times New Roman;
    font-size: 11px;
}
-->
</style></head>

<body>
<form action="<?php echo $editFormAction?>" method="post" name="form1" id="form1">
  <table border="1" align="center" cellpadding="2" cellspacing="2" bordercolor="#CCCCCC">
    <tr valign="baseline">
      <td align="right" valign="top" nowrap="nowrap">Titulo:</td>
      <td><textarea name="titulo" cols="50"></textarea></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right" valign="top">Margenes:</td>
      <td>
      <input name="imagen" type="checkbox" value="4" />
      Seleccionar si insertas imagen</td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right" valign="top">Ruta:</td>
      <td>
   <?php   
      $value 
""
echo 
"<input name='ruta' type='text' size='50' value='$value' />"
if(
$_POST['campo'] == "") { 
$value "../images/spacer.gif"
}  
      
?> 
</td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right" valign="top">Resumen:</td>
      <td><textarea name="resumen" cols="50" rows="5"></textarea>      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right" valign="top">Contenido:</td>
      <td><textarea name="contenido" cols="50" rows="5"></textarea>      </td>
    </tr>
    <tr valign="baseline">
      <td colspan="2" align="right" nowrap="nowrap"><div align="center">
        <input type="submit" value="Insertar registro" />
      </div></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><p align="center">&nbsp;<a href="<?php echo $logoutAction ?>">Cerrar Sesión</a></p>
      <p><?php  
//guardar como subir_archivos.php 

if (isset($_POST['submit'])) {   
    if(
is_uploaded_file($_FILES['fichero']['tmp_name'])) { 
     
     
     
// me verifica haya sido cargado el archivo  
        
$ruta_destino "images/"
        if(
move_uploaded_file($_FILES['fichero']['tmp_name'], $ruta_destino $_FILES['fichero']['name'])) { // se coloca en su lugar final  
                    
echo "<b>Upload exitoso!. Datos:</b><br>";  
            
            echo 
"Nombre: <i><a href=\"".$ruta_destino $_FILES['fichero']['name']."\">http://www.elcapitolio.net/noticias/images/".$_FILES['fichero']['name']."</a></i><br><br>";  
            
            echo 
"<p>http://www.elcapitolio.net/noticias/images/".$_FILES['fichero']['name']."</p>";
            
            echo 
" <i><img src=\"".$ruta_destino $_FILES['fichero']['name']."\"></i><br><br>";

            
            echo 
"Tipo MIME: <i>".$_FILES['fichero']['type']."</i><br>";  
                    echo 
"Peso: <i>".$_FILES['fichero']['size']." bytes</i><br>";  
                        echo 
"<br><hr><br>";  
                         


//conectamos a la base de datos para almacenar los datos y la ruta del archivo 

mysql_connect('localhost','elcapito_daecorp','seifer')or die ('Ha fallado la conexión: '.mysql_error()); 
mysql_select_db('elcapito_eventos')or die ('Error al seleccionar la Base de Datos: '.mysql_error()); 


  
  
  
 
$nombre_archivo  $_POST["nombre_archivo"]; 
 
$description  $_POST["description"]; 


$query "INSERT INTO archivos  
    VALUES (0,'$nombre_archivo','$description' , '"
.$_FILES['fichero']['name']."','".$_FILES['fichero']['type']."', '".$_FILES['fichero']['size']."')"

                
mysql_query($query) or die(mysql_error()); 
                echo 
"El archivo '".$nombre_archivo."' ha sido registrado de manera satisfactoria.<br />"
                 
     


                      
        }  
    }  
  
// A continuación el formulario  

?> 
<body> 
<form action="<?php echo $_SERVER['PHP_SELF'?>" method="post" enctype="multipart/form-data">  
    Archivo: <input name="fichero" type="file" size="150" maxlength="150">  
    <br> Nombre: <input name="nombre_archivo" type="text" size="70" maxlength="70"> 
    <br> Descripcion: <input name="description" type="text" size="100" maxlength="250"> 
    <br> 
  <input name="submit" type="submit" value="Upload!">   
</form> 
<form id="form2" name="form2" method="post" action="">
  <label>Embonar Codigo:<br />
  <textarea name="textarea" id="textarea" cols="80" rows="2"><img src="" width="130" height="120" hspace="5" vspace="5" align="left" /></textarea>
  </label>
</form>
<p>&nbsp;</p>
    </body> </p>
    <p>&nbsp;</p></td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result
($ultimas);
?>
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México