简体   繁体   中英

Can not update photo into a database using PDO

the code save the photo inside the folder in root, but in the database not save the rute into the photo...can you help me with this.

here the form:

<form class='form-horizontal' method='post' action='' enctype='multipart/form-data'>
            <fieldset>
            <legend><i class='icon32 icon-wrench'></i>Configuración General del Sistema</legend>

            <div class='control-group'>
                <label class='control-label' for='typeahead'>Nombre de la Clínica</label>
                <div class='controls'>
                    <input type='text' class='span6 typeahead' name='nombre_clinica' 
                        value='<?php echo $nombre_clinica;  ?>' />
                </div>
            </div>
            <div class='control-group'>
                <label class='control-label' for='typeahead'>Dirección</label>
                <div class='controls'>
                    <input type='text' class='span6 typeahead' name='direccion' 
                        value='<?php echo $direccion;  ?>' />
                </div>
            </div>
            <div class='control-group'>
                <label class='control-label' for='typeahead'>Número de Teléfono</label>
                <div class='controls'>
                    <input type='text' class='span6 typeahead' name='telefono_clinica' 
                        value='<?php echo $telefono_clinica; ?>' />
                </div>
            </div>
            <div class='control-group'>
                <label class='control-label' for='typeahead'>Viñeta de página web</label>
                <div class='controls'>
                    <input type='text' class='span6 typeahead' name='titulo_clinica' 
                        value='<?php echo $titulo_clinica; ?>' />
                </div>
            </div>
            <div class='control-group'>
                <label class='control-label' for='typeahead'>Logo Clínica</label>
                <div class='controls'>
                    <input type="hidden" name="MAX_FILE_SIZE" value="200000" /> <input data-clear-btn="true" class="input-file uniform_on" name="logo" id="fileInput" value="nopic.jpg" type="file" accept="image/png, image/jpeg"/> 
                    <br />
                    <img style='max-height:80px;' src='../images/<?php echo $logo; ?>' />
                </div>
            </div>
            <div class='control-group'>
                <label class='control-label' for='typeahead'>Meta tag del Software clínico</label>
                <div class='controls'>
                    <input type='text' class='span6 typeahead' name='page_meta_tag' 
                        value='<?php echo $page_meta_tag; ?>' />
                </div>
            </div>
            <div class='control-group'>
                <div class='controls'>
            <input type='hidden' name='id' value='<?php echo $id ?>' /><input type='hidden' name='action' value='update' />
            <input type='submit' class='btn btn-primary' value='Actualizar configuracion' />
                </div>
            </div>
            </fieldset>
         </form>

and here is the code:

    <?php
include '../include/update_config.php';

$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);

$action = isset( $_POST['action'] ) ? $_POST['action'] : "";
if($action == "update"){
        try{
move_uploaded_file($_FILES['logo']['tmp_name'], "../images/" . $_FILES['logo']['name']);
             $query = 'update CONFIGURACION set id = :id, nombre_clinica = :nombre_clinica, direccion = :direccion, telefono_clinica = :telefono_clinica, titulo_clinica = :titulo_clinica, logo = :logo, page_meta_tag = :page_meta_tag where id = 0';
                $stmt = $conn->prepare($query);

                $stmt->bindParam(':nombre_clinica', $_POST['nombre_clinica']);
                $stmt->bindParam(':direccion', $_POST['direccion']);
                $stmt->bindParam(':telefono_clinica', $_POST['telefono_clinica']);
                $stmt->bindParam(':titulo_clinica', $_POST['titulo_clinica']);
                $stmt->bindParam(':logo', $_POST['logo']);
                $stmt->bindParam(':page_meta_tag', $_POST['page_meta_tag']);
                $stmt->bindParam(':id', $_POST['id']);

                // Execute the query
                $stmt->execute();

                echo "Registro actualizado correctamente.";

        }catch(PDOException $exception){ 
                echo "Error: " . $exception->getMessage();
        }
}

try {

        $query = "select nombre_clinica, direccion, telefono_clinica, titulo_clinica, logo, page_meta_tag from CONFIGURACION where id = 0";
        $stmt = $conn->prepare( $query );

        $stmt->bindParam(1, $_REQUEST['id']);

        $stmt->execute();

        $row = $stmt->fetch(PDO::FETCH_ASSOC);

        $id = $row['id'];
        $nombre_clinica = $row['nombre_clinica'];
        $direccion = $row['direccion'];
        $telefono_clinica = $row['telefono_clinica'];
        $titulo_clinica = $row['titulo_clinica'];
        $logo = $row['logo'];
        $page_meta_tag = $row['page_meta_tag'];


}catch(PDOException $exception){ 
        echo "Error: " . $exception->getMessage();
}


?>

the photo is save succesfully in the folder ../images/

$path = "images/" . $_FILES['logo']['name'];
move_uploaded_file($_FILES['logo']['tmp_name'], "../".$path);
...
$stmt->bindParam(':logo', $path);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM