PHP - Como actualizar imagen de mi base de datos

 
Vista:
Imágen de perfil de Mosiah

Como actualizar imagen de mi base de datos

Publicado por Mosiah (42 intervenciones) el 19/12/2013 09:06:17
Hola, tengo un problema, el cual es que no puedo actualizar la imagen que actualmente tengo en mi base de datos, tengo el siguiente código:

Quiero aclarar que esto sólo me ocurre cuando quiero actualizar una imagen, si intento actualizar los otros datos, me funciona de maravilla. Espero me puedan ayudar por favor, se los agradecería.

edicion-empresa.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
$id = $_GET['id'];
 
include('config/acceso_db.php');
 
    $query = "select * from clientes where id_cliente = '$id'";
    $result = mysql_query($query);
 
while ($registro = mysql_fetch_array($result)){
 
echo "<div align='center'>
    <table border='0' width='600' style='font-family: Verdana; font-size: 8pt' id='table1'> 
        <tr> 
            <td colspan='2'><h3 align='center'>Actualice los datos que considere</h3></td> 
        </tr> 
        <tr> 
            <td colspan='2'>En los campos del formulario puede ver los valores actuales,  
            si no se cambian los valores se mantienen iguales.</td> 
        </tr> 
<form method='POST' action='modulos/actualizar-cliente-empresa.php'> 
        <tr> 
            <td width='50%'>&nbsp;</td> 
            <td width='50%'>&nbsp;</td> 
        </tr> 
        <tr> 
            <td width='50%'><p align='center'><b>Nombre: </b></td> 
            <td width='50%'><p align='center'><input type='text' name='nombre' size='20' value='".$registro['titulo_cliente']."'></td>
        </tr> 
        <tr> 
            <td width='50%'><p align='center'><b>Enlace</b></td> 
            <td width='50%'><p align='center'><input type='text' name='enlace' size='20' value='".$registro['enlace']."'></td>
        </tr> 
		<tr>
			<td width='50%'><p align='center'><b>Descripcion:</b></td>
			<td width='50%'><p align='center'><textarea name='descripcion' cols='1' rows='2'>".$registro['descripcion']."</textarea></td>
        <tr> 
		<tr>
			<td width='50%'><p align='center'><b>Imagen(Logo):</b></td><br>
			<td width='50%'><img title='".$registro['titulo_cliente']."' heigh='50' width='70' src='../images/clientes/".$registro['imagen']."'/></td>
			<td width='50%'><input type='file' name='img'/></td> 
        <tr> 
            <td width='50%'>&nbsp;</td> 
            <td width='50%'>&nbsp;</td> 
        </tr> 
        <input type='hidden' name='id' value='$id'> 
        <tr> 
            <td width='100%' colspan='2'> 
            <p align='center'> 
            <input type='submit' value='Actualizar datos' name='B1'><input type='reset' value='Restaurar' name='B1'></td> 
        </tr> 
        </form> 
    </table> 
</div> 
";
}
 
	   mysql_free_result($consulta);
	    ?>


actualizar.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
 
$id = $_POST['id'];
 
$nombre_cliente = $_POST['nombre'];
$enlace = $_POST['enlace'];
$fecha = date("d-m-Y");
 
include('../config/acceso_db.php');
 
require_once('../subir-empresa.php');
 
$sSQL="Update clientes Set titulo_cliente='$nombre_cliente',enlace='$enlace',fecha='$fecha',imagen='$nombre' where id_cliente='$id'";
mysql_query($sSQL);
 
echo 'body>
	<script type="text/javascript">
	window.location="../administrar.php?seccion=clientes-empresa";
	</script>
		</body>';
?>

subir-empresa.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
 require_once('config/acceso_db_noticias.php');
error_reporting(E_ALL ^ E_NOTICE);
  $id=$_REQUEST['id'];
$directorio = $_SERVER['DOCUMENT_ROOT'].'../corell/images/clientes/';
 
    // Recibo los datos de la imagen
	$nombre = $_FILES['img']['name'];
  	$tipo = $_FILES['img']['type'];
   	$tamano = $_FILES['img']['size'];
    // Muevo la imagen desde su ubicación
    // temporal al directorio definitivo
    move_uploaded_file($_FILES['img']['tmp_name'],$directorio.$nombre);
	mysql_select_db($bd,$conexion);
	$query="UPDATE clientes SET imagen='$nombre' WHERE id_clientes='$id'";
	$insertar=mysql_query($query,$conexion);
 
?>

PD: ya se que mysql está obsoleto, después actualizo el código a mysqli.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

Como actualizar imagen de mi base de datos

Publicado por Elier (92 intervenciones) el 23/12/2013 15:10:56
Te faltó en el formulario enctype="multipart/form-data"

<form method="POST" action="modulos/actualizar-cliente-empresa.php" enctype="multipart/form-data" >

</form>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar