Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/02/2012, 11:35
Avatar de lukazz
lukazz
 
Fecha de Ingreso: marzo-2011
Mensajes: 88
Antigüedad: 13 años, 1 mes
Puntos: 3
cambiar este codigo php para hacer un update

hola a todosss , me puede ayudar con esto ? este codigo lo que hace es subir la imagen al servidor y los datos de la imagen como el nombre y la descipcion a la base de datos,


ahora lo que necesito es hacer un update que al subir la imagen nueva cambie el nombre que esta en la base de datos por el nombre de la imagen nueva q subi, alguien sabe como hacerlo ?



Código PHP:
<?php require_once('Connections/archivo.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")) {
  
  
////////////// Parte añadida 1 ////////////// 
  //array de archivos disponibles
  
$archivos_disp_ar = array('jpg''jpeg''gif''png');
  
//carpteta donde vamos a guardar la imagen
  
$carpeta 'fotos/';
  
//recibimos el campo de imagen
  
$imagen $_FILES['imagen']['tmp_name'];
  
//guardamos el nombre original de la imagen en una variable
  
$nombrebre_orig $_FILES['imagen']['name'];
  
//el proximo codigo es para ver que extension es la imagen
  
$array_nombre explode('.',$nombrebre_orig);
  
$cuenta_arr_nombre count($array_nombre);
  
$extension strtolower($array_nombre[--$cuenta_arr_nombre]);

  
//validamos la extension
  
if(!in_array($extension$archivos_disp_ar)) $error "Este tipo de archivo no es permitido";
  
  if(empty(
$error)){
  
      
$nombre_nuevo "default." .$extension;
      
$nombre_nuevo_con_carpeta $carpeta.$nombre_nuevo;
      
$mover_archivos move_uploaded_file($imagen $nombre_nuevo_con_carpeta);

      
chmod($nombre_nuevo_con_carpeta,0777);

$clase "2";
$voto "0";
      
$insertSQL sprintf("INSERT INTO archivos (tipo_archivos, nombre_archivos, archivo_archivos, extension_archivos, fecha_archivos, descripcion,voto,clase) VALUES (%s, %s, %s, %s, NOW(), '".$_POST['descripcion']."', '".$voto."' , '".$clase."' )",
                           
GetSQLValueString($_POST['tipo'], "text"),
                           
GetSQLValueString($_POST['nombre'], "text"),
                           
////////////// Parte añadida ////////////// 
                           
GetSQLValueString($nombre_nuevo"text"),
                           
GetSQLValueString($extension"text"))
                           
///////////////////////////////////////////
                           
;
    
      
mysql_select_db($database_frase$frase);
      
$Result1 mysql_query($insertSQL$frase) or die(mysql_error());
    }
}


mysql_select_db($database_frase$frase);
$query_Recordset1 "SELECT * FROM archivos WHERE tipo_archivos = 'general' ORDER BY fecha_archivos DESC";
$Recordset1 mysql_query($query_Recordset1$frase) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);
?>
<?php 
if(!empty($error)) echo $error?>
<?php 
if ($_GET["r"]) 
{
  echo
'<style type="text/css">
.carga {
    visibility:hidden;
    position:relative; width:416px; height:155px; z-index:1; border:1px solid #B6B7B7; color:#000; margin-bottom:10px; font-weight: bold; font-size: 18px; font-family: Verdana, Geneva, sans-serif;
}
</style>
<script language="Javascript">

location.href="index.php";

</script>
'
;
}
else
{
    echo
'<style type="text/css">
.carga {
    
    position:relative; width:416px; height:155px; z-index:1; border:1px solid #B6B7B7; color:#000; margin-bottom:10px; font-weight: bold; font-size: 18px; font-family: Verdana, Geneva, sans-serif;
}
</style>'
;
}
?>


<div  class="carga">
  <form action="<?php echo $editFormAction?>r=red" method="POST" enctype="multipart/form-data" name="form1" id="form1">
  <p>
    <label for="imagen"> Tu nombre:</label>
  </p>
  <p>
    <input type="text" name="nombre" id="nombre">
  </p>
  <p>
    <label for="imagen">Descripcion:<br />
      <span style="text-align: center"></span> </label>
    
    <input type="text" name="descripcion" id="descripcion">
    <span style="text-align: center"></span> </p>
  <p>
    <label for="imagen">Imagen:<br />
  </label>

    <input type="file" name="imagen" id="imagen">
</p>
  <p>    <span class="enviar">
      <input type="submit" name="enviar" id="enviar" value="Enviar">
      </span>
    <input name="tipo" type="hidden" id="tipo" value="general">
    <input type="hidden" name="MM_insert" value="form1">
  </p>
</form>
</div>
<?php
mysql_free_result
($Recordset1);
?>