Foros del Web » Programando para Internet » PHP »

Insertar valor en la base de datos

Estas en el tema de Insertar valor en la base de datos en el foro de PHP en Foros del Web. Código PHP: <?php if (! function_exists ( "GetSQLValueString" )) { function  GetSQLValueString ( $theValue ,  $theType ,  $theDefinedValue  =  "" ,  $theNotDefinedValue  =  "" )  {    ...
  #1 (permalink)  
Antiguo 18/08/2008, 19:17
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Insertar valor en la base de datos

Código PHP:
<?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 (id, categoria, titulo, imagen, ruta, resumen, contenido, escritor, `date`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['id'], "int"),
                       
GetSQLValueString($_POST['categoria'], "text"),
                       
GetSQLValueString($_POST['titulo'], "text"),
                       
GetSQLValueString($_POST['imagen'], "text"),
                       
GetSQLValueString($_POST['ruta'], "text"),
                       
GetSQLValueString($_POST['resumen'], "text"),
                       
GetSQLValueString($_POST['contenido'], "text"),
                       
GetSQLValueString($_POST['escritor'], "text"),
                       
GetSQLValueString($_POST['date'], "date"));

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

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

mysql_select_db($database_portadas$portadas);
$query_ultimas "SELECT * FROM noticias";
$ultimas mysql_query($query_ultimas$portadas) or die(mysql_error());
$row_ultimas mysql_fetch_assoc($ultimas);
$totalRows_ultimas mysql_num_rows($ultimas);
?>

Lo que quiero es que en vez de agarrar la ruta del formulario

me inserte el valor que tiene ".$_FILES['fichero']['name']." que es el archivo que subi con el formulario anterio... alguien sabe que puedo hacer

$insertSQL = sprintf("INSERT INTO noticias (id, categoria, titulo, imagen, ruta, resumen, contenido, escritor, `date`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id'], "int"),
GetSQLValueString($_POST['categoria'], "text"),
GetSQLValueString($_POST['titulo'], "text"),
GetSQLValueString($_POST['imagen'], "text"),
GetSQLValueString($_POST['ruta'], "text"),
GetSQLValueString($_POST['resumen'], "text"),
GetSQLValueString($_POST['contenido'], "text"),
GetSQLValueString($_POST['escritor'], "text"),
GetSQLValueString($_POST['date'], "date"));
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México
  #2 (permalink)  
Antiguo 18/08/2008, 19:26
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: Insertar valor en la base de datos

Ejemplo:
"INSERT INTO noticias (ruta) VALUES ('".$_FILES['fichero']['name']."')";
  #3 (permalink)  
Antiguo 18/08/2008, 19:35
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Respuesta: Insertar valor en la base de datos

Cita:
Iniciado por Ronruby Ver Mensaje
Ejemplo:
"INSERT INTO noticias (ruta) VALUES ('".$_FILES['fichero']['name']."')";
Ok... esto si lo se hacer... pero que pasa con el resto de los campos?? quiero en el mismo registro que me aparezca el campo ruta y los valores que recoje del form1


como le hago
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México
  #4 (permalink)  
Antiguo 18/08/2008, 22:36
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Respuesta: Insertar valor en la base de datos

hize esto ...


Código PHP:
$ruta $_FILES['fichero']['name'];
if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO noticias (id, categoria, titulo, imagen, ruta, resumen, contenido, escritor, `date`) VALUES (%s, %s, %s, %s, '$ruta', %s, %s, %s, %s)"

pero me marca esto a la hora de correrlo

Column 'resumen' cannot be null

y si le estoy mandando valor para resumen
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México
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 00:35.