upload an image in PHP and save the result in database

0

I tried to upload a profile picture using this code in php and it saves it in the path that I specify but it does not save anything in the database. I am working with wampserver and phpmyadmin .

The code I have is the following:

$imagen = $_FILES['imagen']['name'];
$ruta = "../subidos/" . $_FILES['imagen']['name']; 
$resultado = @move_uploaded_file($_FILES["imagen"]["tmp_name"], $ruta); 


 $modificar=("UPDATE usuario SET nombre = '".$nombre."', pass= '".$password."', 
              escolar = '".$nivel."',nacimiento='".$fecha2."',foto_perfil='".$image."'
             WHERE CodUsua='".$_SESSION["CodUsua"]."'");
    
asked by Carlos Bonilla 20.06.2017 в 17:01
source

2 answers

2

Your code is fine. As I can see, the error is in this part

foto_perfil='".$image."'

You are typing "$ image" and as I read, your variable is called "$ image". Your query should be like this:

$modificar=("UPDATE usuario SET nombre = '".$nombre."', pass= '".$password."', 
          escolar = '".$nivel."',nacimiento='".$fecha2."',foto_perfil='".$imagen."'
         WHERE CodUsua='".$_SESSION["CodUsua"]."'");

And thanks to the collaboration of JackNavaRow, in the future, if you want to show that image to the user or someone else you can use:

<img src="miruta/<?=$imagen?>">
    
answered by 20.06.2017 / 17:06
source
1

Where do you intend to save the profile picture in the database? In the field "photo_profile"?

If so, what I recommend you do in the update is that you save the route in that field: $ route. So when you're going to load the profile picture from the DB only in the fetch you just have to put the     

answered by 20.06.2017 в 17:07