0

I'm having difficulties to insert the value as blob type always empty and the other method can't insert the images in a folder. Please you can show the way out. Thanks! This code is to save the image in a folder and then access it with the name to display, but is not saving the photos to the folder. I edited and include the form here, containing JavaScript and css .It looks some how messy but i'm a beginner. Thanks.

<?php
include("../views/post_form.php");
require("../includes/include.php");
require("../includes/sess_n.php"); 

if ($_SERVER["REQUEST_METHOD"]== "POST")
{
    $usertext = $_POST["usertext"];
    $image = $_FILES['image']['name'];
    $talent =$_POST["talenttype"];

    if(empty($usertext) || empty($image)|| empty($talent))
    {
        die();
    }

    $id = $_SESSION["id"];
    $folder ="images/".basename($_FILES['image']['name']);
    move_uploaded_file($_FILES['image']['tmp_name'],$folder) ;
    $query = mysqli_query($link,"SELECT * FROM `upload` WHERE id = '$id'");
    $upload = mysqli_query($link,"INSERT INTO `upload` (description,image,talent,folder) VALUES('$usertext','$image','$talent','$folder ')");
}
?>

To display, I want the photos to be save to the folder, not saving. I used blob method not inserting into the database.

<?php
include("../views/feeds_form.php");
require("../includes/include.php");
require("../includes/sess_n.php");

$query = mysqli_query($link,"SELECT  * FROM `upload` ");

if ($query === false)
{
    die();
}

echo '<table>';
while ($run = mysqli_fetch_assoc($query)) 
{
    echo '<tr>';
    echo '<td>';?> <img src =" <?php echo $run["image"]; ?>" height=100 width=100> <?php echo '<td>';
    echo '<td>'; echo $run["description"]; echo '<td>';  echo $run["folder"];echo '<td>';
    echo '</tr>';
}
echo '</table>';
?>

The form here.

<?php
include("../public/header.php");
?>

<div><title>post</title></div>
<style>
.form-inline
{
    text-align: center;
    margin-bottom: 50px;
}
</style>
<script type="text/javascript">
function validate(){
    var usertext = document.getElementById("usertext");
    var talent = document.getElementById("talenttype");
    var image = document.getElementById("image");

    if (usertext.value === "" && talent.value === "" && image.value ==="") 
    {
        alert("Field Must Not be Empty");
    }
}
</script>

<form class="form-inline"  method ="POST" action ="post.php" enctype="multipart/form-data" onsubmit= "return validate();">
    <div class="form-group">
        <label class="sr-only" for="exampleInputEmail3"> </label>
        <textarea class="form-control" id = "usertext" name ="usertext" rows="5" placeholder="Describe Person Here"></textarea> <br><hr>
        <label class="sr-only" for="exampleInputEmail3"></label><br>
        <div class="form-group">
            <label for="exampleInputPassword1"></label>
            <input type="file" class="form-control" id = "image" id="exampleInputPassword1" name="image" placeholder="image">
        </div> <br><br><br> <hr>
        <div class="form-group">
            <label for="exampleInputPassword1"></label>
            <input type="text" class="form-control" id = "talenttype" id="exampleInputPassword1" name = "talenttype" placeholder="Talent-Type"><br><br>
        </div> <hr>
        <div>
            <button type="submit"  name ="post" class="btn btn-default">Post</button><br>
        </div>
    </div>
</form>

<?php
include("../public/footer.php");
?>
EhsanT
  • 2,077
  • 3
  • 27
  • 31
  • Using a blob has a very similar outcome as storing it in an ordinary file only you lose out on a lot of performance gains as common web servers are excellent at serving up static files. I'd focus on using files; what actually is your problem? What error(s) do you get? – Luke Briggs Jan 02 '17 at 02:21
  • Show the code you are using to save to the database – RiggsFolly Jan 02 '17 at 02:40
  • Please read [What topics can I ask about](http://stackoverflow.com/help/on-topic) and [How to ask a good question](http://stackoverflow.com/help/how-to-ask) And [the perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) And how to create a [Minimal, Complete and Verifiable example](http://stackoverflow.com/help/mcve) – RiggsFolly Jan 02 '17 at 02:40
  • Dont' save files in a database. http://stackoverflow.com/a/41235395/267540 – e4c5 Jan 02 '17 at 02:46
  • i edited the question. I can't get the photo to be saved in the folder, even using blob can't save the file in the database only empty. – Abdullahi Abubakar Haruna Jan 02 '17 at 03:35
  • maybe your html form's failing. check for permissions / path on the upload folder also. Error reporting will help you here as well as editing your question to include the form. – Funk Forty Niner Jan 02 '17 at 03:45
  • and the space in this `'$folder '` counts as a character. – Funk Forty Niner Jan 02 '17 at 03:48
  • keep on trying... Thanks – Abdullahi Abubakar Haruna Jan 02 '17 at 03:57
  • I'm getting move_uploade_file permission denied on line 23. What should be the problem?@Fred-ii- – Abdullahi Abubakar Haruna Jan 02 '17 at 04:29
  • That probably means the host you're using doesn't allow uploaded files. Which host is it? Also your PHP puts way too much trust in your users; they could do major damage to your server via SQL injections and with edited filenames. – Luke Briggs Jan 02 '17 at 05:40
  • I'm using XAMPP on my local machine with sublime text. I'm a beginner and nit going live with it. What is host? – Abdullahi Abubakar Haruna Jan 02 '17 at 05:48
  • If it's local then it'll be a folder permissions issue. Make sure your `images` folder can be read/written to. If you're on a Mac [see this](http://stackoverflow.com/a/31919367/2873896). 'Host' means a webhost - many webhosts don't allow uploads by default. – Luke Briggs Jan 02 '17 at 07:22
  • Also don't ignore those security issues - a site you do put online will get major problems *very* quickly with holes like those. Never trust anything the user sends - learn [about SQL injection](http://bobby-tables.com/about) and [how to avoid it](http://bobby-tables.com/php). `$_FILES['image']['name']` could be literally anything too (allowing a hacker to potentially overwrite your website and run whatever they want). – Luke Briggs Jan 02 '17 at 07:27
  • Another tip: On StackOverflow, use usernames to notify somebody (e.g. @LukeBriggs to notify me). You'll get responses a lot faster if you do that :) – Luke Briggs Jan 02 '17 at 07:30
  • I got@LukeBriggs.. Thanks – Abdullahi Abubakar Haruna Jan 02 '17 at 11:20

1 Answers1

0

I was having permission issues, the images folder permission was changed. That solves everything. Thanks!