Edit image stored as blob php

0

Hello, I'm here to do a job and I'm having a problem with my code. For example I have two fields of my image and another with information after I have entered information for the database I edit only information about the image, edit the information but also erase the image of the database because I do not edit the image, but I want it to be possible to edit only one field without editing the image. I do not know if I was explicit enough but ask questions if necessary.

Code

    <?php 
    ob_start();
    include("../login/session.php");
    if(isset($_GET['id'])){
        $id=$_GET['id'];
        //query to check if the user loged is is the one that created the post.
        $fetch = mysqli_query($link, "Select * from conteudo where d_autor ='{$_SESSION['login_username']}' and d_id='$id'");
        $count=mysqli_num_rows($fetch);
            if($count!="") {
                    if(isset($_POST['update'])){
                            echo '<script>console.log("$_POST=")</script>';
                            $imgData= addslashes(file_get_contents($_FILES['userImage']['tmp_name']));
                            $imageProperties = getimageSize($_FILES['userImage']['tmp_name']);
                            $portal = mysqli_real_escape_string($link, $_POST['field1']);
                            $datacri = mysqli_real_escape_string($link, $_POST['field2']);
                            $datacri = date('Y-m-d', strtotime(str_replace('-', '/', $datacri)));
                            $datapub = mysqli_real_escape_string($link, $_POST['field3']);
                            $datapub = date('Y-m-d', strtotime(str_replace('-', '/', $datapub)));
                            $titulo = mysqli_real_escape_string($link, $_POST['field4']);
                            $keyword = mysqli_real_escape_string($link, $_POST['field5']);
                            $hashtags = mysqli_real_escape_string($link, $_POST['field6']);
                            $info = mysqli_real_escape_string($link, $_POST['field7']);
                                if (!mysqli_query($link,"UPDATE conteudo SET 
                                d_portal='$portal', d_datacri='$datacri', d_datapub='$datapub', d_titulo='$titulo', d_keyword='$keyword', d_imageType='{$imageProperties['mime']}' , d_imageData='{$imgData}', d_hashtags='$hashtags', d_info='$info' WHERE d_id='$id'")){
                                echo("Error description: " . mysqli_error($link));
                                }}
            }else{
                echo '<script type="text/javascript"> alert("Não tem permissão para eliminar os pedidos que não foram criados por si!"); </script>';
                header('Refresh: 0; URL=../php/c_view.php');
                }}
    ?>
<?php
$getselect=mysqli_query($link,"SELECT * FROM conteudo WHERE d_id='$id'");
    while($profile=mysqli_fetch_array($getselect)){
        $portal=$profile['d_portal'];
        $datacri=$profile['d_datacri'];
        $datacri = date('Y-m-d', strtotime(str_replace('-', '/', $datacri)));
        $datapub=$profile['d_datapub'];
        $datapub = date('Y-m-d', strtotime(str_replace('-', '/', $datapub)));
        $titulo=$profile['d_titulo'];
        $keywords=$profile['d_keyword'];
        $hashtags=$profile['d_hashtags'];
        $info=$profile['d_info'];
        $autor=$profile['d_autor'];
    ?>

HTML:

<html>
                <div class="display">
                    <form action="" method="post" name="insertform" enctype='multipart/form-data'>
                        <p>
                            <legend><span class="number" >1</span>Editar pedido</legend>
                            <label class="label1" for="name"  id="preinput"> Portal</label>
                                <?php
                                $result = $link->query("select po_id, po_nome from portais");
                                    echo "<html>";
                                    echo "<body>";
                                    echo "<select name='field1' name='po_id'>";
                                    echo "<option value=''>----Selecione um Portal----</option>";
                                        while ($row = $result->fetch_assoc()) {
                                            unset($id, $name);
                                            $id = $row['po_id'];
                                            $name = $row['po_nome'];
                                            echo '<option value="'.$name.'">'.$name.'</option>';
                                            echo "</select>";
                                            echo "</body>";
                                            echo "</html>";}
        ?>
                        </p>
                        <p>
                            <label class="label1" for="name"  id="preinput"> Data de criacao:</label>
                            <input class="textbox" type="date" name="field2" required placeholder="Enter your name" value="<?php echo $datacri; ?>" id="inputid" />
                        </p>
                        <p>
                            <label class="label1" for="name"  id="preinput"> Data de publicacao</label>
                            <input class="textbox" type="date" name="field3" required placeholder="Enter your name" value="<?php echo $datapub; ?>" id="inputid" />
                        </p>
                        <p>
                            <label class="label1" for="name"  id="preinput"> Titulo</label>
                            <input class="textbox" type="text" name="field4" required placeholder="Enter your name" value="<?php echo $titulo; ?>" id="inputid" />
                        </p>
                        <p>
                        <label class="label1" for="name"  id="preinput"> Keywords</label>
                        <input class="textbox" type="text" name="field5" required placeholder="Enter your name" value="<?php echo $keywords; ?>" id="inputid" />
                        </p>
                            <input type="file" name="userImage" accept="image/*" class="inputFile"> <p> </p>
                        <p>
                            <label class="label1" for="name"  id="preinput"> Hashtags</label>
                            <input class="textbox" type="text" name="field6" required placeholder="Enter your name" value="<?php echo $hashtags; ?>" id="inputid" />
                        </p>
                        <p>
                            <label class="label1" for="name"  id="preinput"> Info</label>
                            <textarea name="field7" size="200"><?php echo $info ?></textarea>
                        </p>
                        <p>
                            <input type="submit" name="update" value="Editar" id="inputid1" class="button" />
                        </p>
                    </form>
        <?php } ?>
        </div>
        </body>
        </html>
    
asked by anonymous 13.02.2017 / 13:23

0 answers