Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/10/2007, 13:12
lozonne
 
Fecha de Ingreso: octubre-2007
Mensajes: 8
Antigüedad: 17 años, 3 meses
Puntos: 0
Reemplazar imagen y registro.

Hola a todos

No soy programador, pero con ayuda de dreamweaver y scripts que encuentro por ahí casi tengo terminado un mini cms.

Tengo un código que casi consigue lo que busco:

- Sube una imagen al servidor, la copia en una carpeta.
- Le añade el campo "nombre_pr" al nombre para evitar la coincidencia.
- Actualiza el registro que tenga id=2.

Es un página detalle por lo que me gustaría que actualizase la id escogida, he hecho varias pruebas pero soy incapaz.

Me imagino que para los que programais ésto sera muiy sencillo, copio y pego el código, la clave podría estar aquí, ¿no?:

Código PHP:
$fila=2;
          
$query "UPDATE sc_product SET nombre_pr='$nombre_pr', orden_pr='$orden_pr', texto_pr='$texto_pr', enlace='$enlace', foto_pr='$upload_file' WHERE id = $fila"
        
mysql_query($query); 
Si pudierais ayudarme me haríais un gran favor, gracias de antemano.

Código PHP:
<?php require_once('../Connections/conn_scorp.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;
}
}

mysql_select_db($database_conn_scorp$conn_scorp);
$query_Recordset1 sprintf("SELECT * FROM sc_product WHERE id = %s"GetSQLValueString($colname_Recordset1"int"));
$Recordset1 mysql_query($query_Recordset1$conn_scorp) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);

if (isset(
$_POST['enviar'])) {

    
//$tipo_archivo = $HTTP_POST_FILES['userfile']['type'];
    
$nombre_pr $_POST['nombre_pr'];
    
$orden_pr $_POST['orden_pr'];
    
$texto_pr $_POST['texto_pr'];
    
$enlace $_POST['enlace'];
    
$upload_dir '../img/bbdd/';
    
//$id_bbdd= $row_Recordset1['id']; no chuta
    //$id_bbdd= GetSQLValueString($_POST['id'], "int"); no chuta, null
    
$upload_file $upload_dir $nombre_pr $_FILES['foto_pr']['name'];
    
//$imagen = $_FILES['foto_pr']['name'];
    
    
    

    
if (move_uploaded_file($_FILES['foto_pr']['tmp_name'], $upload_file)) {
          
        
// La imagen se subio correctamente, entonces ingresamos los datos en la db
        
chmod($upload_file0777);
        
//rename($upload_file, $id); no funciona
        //$fila = $_GET['recordID'];
        //$fila = GetSQLValueString($_POST['id'], "int");
        
$fila=2;
        
$query "UPDATE sc_product SET nombre_pr='$nombre_pr', orden_pr='$orden_pr', texto_pr='$texto_pr', enlace='$enlace', foto_pr='$upload_file' WHERE id = $fila"
        
mysql_query($query);
        
header ("Location:listado_productos.php"); 

        

    } else {
           echo (
"Algun error al subir la imagen<br><a href='listado_productos.php'>volver</a>");
    }


}
?>

<?php
mysql_free_result
($Recordset1);
?>

Última edición por lozonne; 25/10/2007 a las 16:12 Razón: Envolver codigo con etiqueta php